It seems like a good idea to always supply a null terminator, even on
error.
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,