From 5b220b3e9159d523211f82df81c3b3a7ee2021a0 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Wed, 18 Feb 2009 23:51:35 +0000 Subject: 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 --- main/strings.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'main/strings.c') diff --git a/main/strings.c b/main/strings.c index bdf007fc3..5547e54a9 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)) { -- cgit v1.2.3