GnuTLS does not build on OS X 10.6 due to incompatibility with snprintf macro

Nikos Mavrogiannopoulos nmav at
Sat Jan 15 14:08:43 CET 2011

On 12/29/2010 05:26 AM, Camillo Lugaresi wrote:
> Code built with gcc on Mac OS X 10.6 uses the object size checking feature of gcc by default (<>). This involves redefining several functions as macros; one of these functions is snprintf:
> 	#define snprintf(str, len, ...) \
>  	 __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
> The usage of snprintf in src/serv.c in gnutls-2.10.4 is not compatible with that macro. serv.c attempts to use a macro (tmp2) that expands into two different arguments:
> 	#define tmp2 &http_buffer[strlen(http_buffer)], len-strlen(http_buffer)
> 	snprintf (tmp2, "%.2X", sesid[i]);
> Due to how nested macro evaluation works, the snprintf macro sees tmp2 as a single argument, and copies it into __darwin_obsz(); then, when tmp2 is expanded, __darwin_obsz has two arguments, but it is only defined for one, and the result is a compilation error.
> One way to work around this issue might be to define _FORTIFY_SOURCE=0 so that the snprintf macro is not defined, or simply doing an #undef snprintf for that file, but it seems safer and more portable to split tmp2 into two macros. I append a patch that does so.

 I've applied a fix in the repository. Thank you for reporting that.


More information about the Gnutls-devel mailing list