From cc3c5da9119384feee8480d5663270d041f3c03f Mon Sep 17 00:00:00 2001 From: borutr Date: Mon, 22 May 2006 19:47:32 +0000 Subject: [PATCH] * support/Util/dbuf.c: fixed bug #1489008 fix dbuf_c_str(), second try. Thanks Stas Sergeev once more. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4184 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 5 +++++ support/Util/dbuf.c | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c13a70c..a58aafcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-05-22 Borut Razem + + * support/Util/dbuf.c: fixed bug #1489008 fix dbuf_c_str(), + second try. Thanks Stas Sergeev once more. + 2006-05-21 Maarten Brock * src/hc08/gen.c (transferAopAop): aop forced to stack was not restored, diff --git a/support/Util/dbuf.c b/support/Util/dbuf.c index da52a61e..5ee200ac 100644 --- a/support/Util/dbuf.c +++ b/support/Util/dbuf.c @@ -1,6 +1,6 @@ /* dbuf.c - Dynamic buffer implementation - version 1.1.2, May 17th, 2006 + version 1.1.2, May 22th, 2006 Copyright (c) 2002-2006 Borut Razem @@ -44,8 +44,10 @@ static int dbuf_expand(struct dbuf_s *dbuf, size_t size) if (dbuf->len + size > dbuf->alloc) { /* new_allocated_size = current_allocated_size * 2^n */ /* can this be optimized? */ - while (dbuf->len + size >= dbuf->alloc) + do { dbuf->alloc += dbuf->alloc; + } + while (dbuf->len + size > dbuf->alloc); if ((dbuf->buf = realloc(dbuf->buf, dbuf->alloc)) == NULL) return 0; @@ -145,12 +147,8 @@ const char *dbuf_c_str(struct dbuf_s *dbuf) assert(dbuf->alloc != 0); assert(dbuf->buf != NULL); - /* only if not already null terminated */ - if (dbuf->len == dbuf->alloc || - ((char *)dbuf->buf)[dbuf->len] != '\0') { - dbuf_expand(dbuf, 1); - ((char *)dbuf->buf)[dbuf->len] = '\0'; - } + dbuf_expand(dbuf, 1); + ((char *)dbuf->buf)[dbuf->len] = '\0'; return dbuf->buf; } -- 2.30.2