Fix printf format string for 32-bit systems

The C standard defines the difference between two (char*) pointers is
defined to be either short, int or long.  Not long long (64 bits).  On
64-bit systems, logging "%"PRIhttp_size_t (int64_t) for pointer
difference works by coincidence because a long or int is 64 bits, but
causes SEGV on 32 bit platforms.

The portable solution is to log pointer differences using "%d" and
explicitly cast the pointer difference to (int) in the arg list, or
"%ld" and cast it to (long).
This commit is contained in:
Andrew Bettison 2013-11-04 18:19:56 +10:30
parent 5e756bec1e
commit e61466b815

View File

@ -75,10 +75,10 @@ static struct profile_total http_server_stats = {
#define DEBUG_DUMP_PARSER(r) do { \
if (config.debug.httpd) \
DEBUGF("parsed %"PRIhttp_size_t" %s cursor %"PRIhttp_size_t" %s end %"PRIhttp_size_t" remain %"PRIhttp_size_t, \
r->parsed - r->received, alloca_toprint(-1, r->parsed, r->cursor - r->parsed), \
r->cursor - r->received, alloca_toprint(50, r->cursor, r->end - r->cursor), \
r->end - r->received, \
DEBUGF("parsed %d %s cursor %d %s end %d remain %"PRIhttp_size_t, \
(int)(r->parsed - r->received), alloca_toprint(-1, r->parsed, r->cursor - r->parsed), \
(int)(r->cursor - r->received), alloca_toprint(50, r->cursor, r->end - r->cursor), \
(int)(r->end - r->received), \
r->request_content_remaining \
); \
} while (0)