[Python-Dev] test_builtin failing? or just 64-bit platforms (original) (raw)

Tim Peters tim.one@home.com
Fri, 30 Nov 2001 22:42:58 -0500


Hm, snprintf is supposed to truncate the result,

According to C99, yes, but MS has its own pre-C99 snprintf semantics, and glibc has had at least two different versions.

but it seems that here it refused to do anything. Maybe PyOSsnprintf should be a wrapper that checks the return value of snprintf?

Check it for what? We can't (at least not yet) count on uniform behavior across platform snprintf implementations.

I noticed that none of the recently checked-in PyOSsnprintf calls have their return value checked,

They were all derived (and most mindlessly) from existing sprintf calls that didn't check either. A goal of this transformation was to change as little as possible.

and I think it's better to leave it that way (since in many cases we really don't know what to do instead) -- maybe PyOSsnprintf should even return void (or does it already?).

The comments suggest it wants to return the C99-defined value (an int, < 0 for an encoding error, else the number of characters (excluding \0) written if the size is big enough, else the number of characters that would have been written (excluding \0) had size been big enough. So the output was converted in full iff the return value is non-negative and strictly less than the size passed in. That's fine by me, and I'll note that MS snprintf meets that much too (if size isn't big enough, it returns a negative result). So perhaps in a debug build PyOS_snprintf could assert that the returned value is non-negative and less than the passed-in size ...