[llvm-commits] [llvm] r91842 - /llvm/trunk/include/llvm/Support/Format.h
Michael Beck
mm.beck at gmx.net
Tue Dec 22 13:15:25 PST 2009
> Hello, Michael
>
>> if (res == buff_size) {
>> // '\0' was not written, do it
> Shouldn't we return an error in such situation?
Yep should return res, not res-1, this is the correct way:
int snprintf(char *buffer, int buff_size, const char *format, ...) {
va_list args;
va_start(args, format);
int res = vsnprintf(buffer, buff_size, format, args);
va_end(args);
// pre vc2005sp1 runtime versions return negative values in case of error
if (res < 0)
return res;
if (res >= buff_size) {
// '\0' was not written, do it
buffer[buff_size - 1] = '\0';
}
return res;
}
^
--
Michael Beck
More information about the llvm-commits
mailing list