From: Simon Date: Fri, 27 Mar 2020 14:16:44 +0000 (+0000) Subject: 12326 Refactor loc_stringpool_append function for null ptr increment. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2F12326;p=people%2Fsennis%2Flibloc.git 12326 Refactor loc_stringpool_append function for null ptr increment. --- diff --git a/src/stringpool.c b/src/stringpool.c index e43c4cb..ecac0f6 100644 --- a/src/stringpool.c +++ b/src/stringpool.c @@ -224,11 +224,23 @@ static off_t loc_stringpool_append(struct loc_stringpool* pool, const char* stri off_t offset = loc_stringpool_get_offset(pool, pool->pos); // Copy string byte by byte - while (*string) - *pool->pos++ = *string++; + while (*string) { + if(pool->pos) { + *pool->pos++ = *string++; + } + else { + *pool->pos = *string++; + pool->pos++; + } + } // Terminate the string - *pool->pos++ = '\0'; + if(pool->pos) { + *pool->pos++ = '\0'; + } + else { + *pool->pos = '\0'; + } return offset; }