You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Marc Slemko <ma...@znep.com> on 1997/01/18 23:02:50 UTC

ap_snprintf and 64-bit machines

After looking at it, I'm not sure there is a problem.

Take the following code:

	int main () {
		char buf[1000];

		snprintf(buf, sizeof(buf), "%u", (int)-1);
		printf("buf = %s\n", buf);
		ap_snprintf(buf, sizeof(buf), "%u", (int)-1);
		printf("buf = %s\n", buf);
	}

On an Alpha running Linux I get:

	buf = 4294967295
	buf = 18446744073709551615

snprintf is the one that seems wrong to me.  I would expect the code to
print 2^64 - 1 like ap_snprintf does, not 2^32 - 1 like snprintf does.
Does snprintf do that on Linux just because some broken programs
assume things will work that way?  What do other 64-bit platforms do?

I _think_ that is the main source of differences.  (well, there
are a whole whack of other differences between the sample output
from my test program and the output you get, but that is because
some of my numbers are generated based on INT_MAX.)

In any case, I don't see it being a problem.

Oh, and "#include <string.h>" should be added to util_snprintf.c me
thinks.