apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject Re: Warning in strings/apr_snprintf.c
Date Fri, 23 May 2008 12:12:47 GMT
On Wed, May 21, 2008 at 07:50:02AM +1000, Bojan Smojver wrote:
> I'm getting this (APR 1.2.x):
> -------------------------------------
> strings/apr_snprintf.c: In function 'apr_vformatter':
> strings/apr_snprintf.c:1253: warning: comparison with string literal
> results in unspecified behavior
> -------------------------------------
> 
> The line is:
> -------------------------------------
> if (prefix_char != NUL && s != S_NULL && s != char_buf)
> -------------------------------------
> 
> Where s is pointer to char and S_NULL defined as "null".
> 
> We really want to do this here, right? Just checking...

Interesting - is that gcc 4.3?  The code is bogus because it assumes all 
the expansions of the macro result in a string with the same address; 
does this patch fix the warning?

Index: strings/apr_snprintf.c
===================================================================
--- strings/apr_snprintf.c	(revision 659512)
+++ strings/apr_snprintf.c	(working copy)
@@ -54,7 +54,8 @@
 #endif
 #define NUL '\0'
 
-#define S_NULL "(null)"
+static const char null_string[] = "(null)";
+#define S_NULL ((char *)null_string)
 #define S_NULL_LEN 6
 
 #define FLOAT_DIGITS 6


Mime
View raw message