diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-07-14 07:34:34 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-07-14 07:34:34 +0000 |
commit | 4e18ef688947854313b99f35aa30c0e7d8ae29cd (patch) | |
tree | 54b0d7240765bc43ef378f171a536e6bc7d206d9 /apps/app_striplsd.c | |
parent | 59d780973e0c1aab681be9dcba1baa2706caf92f (diff) |
Merge rgagnon's pedantic string changes (apps n-z) (bug #2038)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3429 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_striplsd.c')
-rwxr-xr-x | apps/app_striplsd.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/apps/app_striplsd.c b/apps/app_striplsd.c index 600f0bdbf..82d513f85 100755 --- a/apps/app_striplsd.c +++ b/apps/app_striplsd.c @@ -45,16 +45,27 @@ LOCAL_USER_DECL; static int striplsd_exec(struct ast_channel *chan, void *data) { - char newexten[AST_MAX_EXTENSION] = ""; - if (!data || !atoi(data)) { - ast_log(LOG_DEBUG, "Ignoring, since number of digits to strip is 0\n"); - return 0; - } - if (strlen(chan->exten) > atoi(data)) { - strncpy(newexten, chan->exten, strlen(chan->exten)-atoi(data)); - } - strncpy(chan->exten, newexten, sizeof(chan->exten)-1); - return 0; + char newexten[AST_MAX_EXTENSION] = ""; + int maxbytes = 0; + int stripcount = 0; + int extlen = strlen(chan->exten); + + maxbytes = sizeof(newexten) - 1; + if (data) { + stripcount = atoi(data); + } + if (!stripcount) { + ast_log(LOG_DEBUG, "Ignoring, since number of digits to strip is 0\n"); + return 0; + } + if (extlen > stripcount) { + if (extlen - stripcount <= maxbytes) { + maxbytes = extlen - stripcount; + } + strncpy(newexten, chan->exten, maxbytes); + } + strncpy(chan->exten, newexten, sizeof(chan->exten)-1); + return 0; } int unload_module(void) |