Commit d7e10f72 authored by vasil's avatar vasil

snprintf() should always return non-negative result. According to

Microsoft documentation about _vscprintf():

  If format is a null pointer, the invalid parameter handler is invoked,
  as described in Parameter Validation. If execution is allowed to
  continue, the functions return -1 and set errno to EINVAL.

The UNIX variant of snprintf() segfaults if format is a NULL pointer
(similar to strlen(NULL) for example), so it is better to conform to
this behavior and crash our custom Windows version instead of
returning -1. Noone would expect -1 to be returned from snprintf().

Cosmetic: Add a space after typecast.

Approved by:	Marko
parent 2ee633f8
...@@ -528,15 +528,12 @@ ut_snprintf( ...@@ -528,15 +528,12 @@ ut_snprintf(
va_start(ap2, fmt); va_start(ap2, fmt);
res = _vscprintf(fmt, ap1); res = _vscprintf(fmt, ap1);
ut_a(res != -1);
if (res == -1) {
return(-1);
}
if (size > 0) { if (size > 0) {
_vsnprintf(str, size, fmt, ap2); _vsnprintf(str, size, fmt, ap2);
if ((size_t)res >= size) { if ((size_t) res >= size) {
str[size - 1] = '\0'; str[size - 1] = '\0';
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment