Code review comment for lp:~laurynas-biveinis/percona-server/bug810272

Revision history for this message
Alexey Kopytov (akopytov) wrote :

According to the C99, Linux and BSD man pages, snprintf(buf, n, ...) writes at most (n-1) characters excluding the terminating zero, always produces a zero-terminated string, and returns values >= n if and only if the output was truncated. So it's not clear what extending the buffer by 1 byte has to do with overflow detection.

Windows, however, is a different creature (surprise, surprise!). In case of overflow, it returns a negative value and does not add the terminating zero.

Which makes snprintf() unusable for portable applications. That's why my_snprintf() is used (5.1 has a few places when the C library snprintf() is used, but they were all fixed in 5.5).

Now the problem with my_snprintf() is that it does not indicate an overflow. That is, it always produces a zero-terminated string and writes at most n characters including the terminating zero. But it always returns the number of characters written, excluding the terminating zero, i.e. at most (n-1).

What I suggest is that we simply get rid of that overflow detection check. Is it really that important to print "TOO BIG STRING" if time gets truncated? I don't think so.

review: Needs Fixing

« Back to merge proposal