ancruna / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

printf format string type errors #295

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Various printf-like functions are passed size_t values for the length in "%.*s" 
formats, where int is required instead. The attached patch (relative to a 
slightly modified version of rev 77615121d235) casts them to int.

GCC warns about these incorrect types if you add some annotated declarations 
like:

#define PRINTF_ARGS(fmtpos) __attribute__ ((format (printf, fmtpos, fmtpos+1)))
#define VPRINTF_ARGS(fmtpos) __attribute__ ((format (printf, fmtpos, 0)))
static int mg_vsnprintf(struct mg_connection *conn, char *buf, size_t buflen, 
const char *fmt, va_list ap) VPRINTF_ARGS(4);
static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen, 
const char *fmt, ...) PRINTF_ARGS(4);
static void cry(struct mg_connection *conn, const char *fmt, ...) 
PRINTF_ARGS(2);
static void send_http_error(struct mg_connection *conn, int status, const char 
*reason, const char *fmt, ...) PRINTF_ARGS(4);

Original issue reported on code.google.com by exc...@gmail.com on 13 Nov 2011 at 6:07

Attachments:

GoogleCodeExporter commented 9 years ago
Submitted d2be594, thank you.

Original comment by valenok on 23 Sep 2012 at 12:36