From b7da2544e1d967b9c3afff6cc93686ddeef09b59 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@cs.stanford.edu>
Date: Sat, 23 Apr 2011 12:02:04 -0700
Subject: [PATCH] str: Always null-terminate string in str_format_26adic().

It seems like a good idea to always supply a null terminator, even on
error.
---
 src/libpspp/str.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

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,
-- 
2.30.2