From: Tilghman Lesher Date: Wed, 18 Feb 2009 23:51:35 +0000 (+0000) Subject: Handle negative length and eliminate a condition that is always true. X-Git-Tag: 1.6.2.0-beta1~173 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b220b3e9159d523211f82df81c3b3a7ee2021a0;p=thirdparty%2Fasterisk.git Handle negative length and eliminate a condition that is always true. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@177287 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/strings.c b/main/strings.c index bdf007fc3a..5547e54a99 100644 --- a/main/strings.c +++ b/main/strings.c @@ -114,8 +114,10 @@ char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, si int dynamic = 0; char *ptr = append ? &((*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED]) : (*buf)->__AST_STR_STR; - if (!maxlen) { - dynamic = 1; + if (maxlen < 1) { + if (maxlen == 0) { + dynamic = 1; + } maxlen = (*buf)->__AST_STR_LEN; } @@ -140,10 +142,7 @@ char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, si /* What we extended the buffer by */ maxlen = old; - /* Update ptr, if necessary */ - if ((*buf)->__AST_STR_STR != oldbase) { - ptr = ptr - oldbase + (*buf)->__AST_STR_STR; - } + ptr += (*buf)->__AST_STR_STR - oldbase; } } if (__builtin_expect(!(maxsrc && maxlen), 0)) {