From: Ben Pfaff Date: Sat, 23 Apr 2011 19:02:04 +0000 (-0700) Subject: str: Always null-terminate string in str_format_26adic(). X-Git-Tag: v0.7.8~45 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7da2544e1d967b9c3afff6cc93686ddeef09b59;p=pspp-builds.git str: Always null-terminate string in str_format_26adic(). It seems like a good idea to always supply a null terminator, even on error. --- diff --git a/src/libpspp/str.c b/src/libpspp/str.c index c630cf9a..7e722c17 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -270,17 +270,22 @@ str_format_26adic (unsigned long int number, char buffer[], size_t size) while (number-- > 0) { if (length >= size) - return false; + goto overflow; buffer[length++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[number % 26]; number /= 26; } if (length >= size) - return false; + goto overflow; buffer[length] = '\0'; buf_reverse (buffer, length); return true; + +overflow: + if (length > 0) + buffer[0] = '\0'; + return false; } /* Sets the SIZE bytes starting at BLOCK to C,