Large memory support

Anatoly Vorobey
Wed, 25 Feb 2004 16:28:03 +0200

On Fri, Feb 20, 2004 at 11:21:06AM -0800, Jason Titus wrote:
> -        pos += sprintf(pos, "STAT limit_maxbytes %u\r\n", settings.maxbytes);
> +        pos += sprintf(pos, "STAT limit_maxbytes %llu\r\n", settings.maxbytes);

This is wrong, because %llu will always expect a 64bit argument, but on
32bit architectures your settings.maxbytes, being a size_t, will be a
32bit argument.
There're two ways to make it right:
a) use the 'z' field width option to sprintf here (and any other place
where we might need to output/input a size_t field) and retain the
size_t type. However, I don't know how standard 'z' is and would
appreciate information about it.
b) use 'unsigned long' instead of size_t, and give %l to sprintf.
"unsigned long" works great because it's 32bit on 32bit architectures
and 64bit on 64bit architectures.

I prefer b) myself, but I may be underappreciating size_t, I'm not sure.

> -            settings.maxbytes = atoi(optarg)*1024*1024;
> +            settings.maxbytes = (size_t) atoi(optarg)* (size_t) 1024* (size_t) 1024;

Most or all of these explicit typecasts shouldn't be necessary.