You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Bojan Smojver <bo...@rexursive.com> on 2008/05/20 23:50:02 UTC
Warning in strings/apr_snprintf.c
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...
--
Bojan
Re: Warning in strings/apr_snprintf.c
Posted by Lucian Adrian Grijincu <lu...@gmail.com>.
I look last night over the function flow and I did not find a case
where there could be
prefix_char != NUL && s == S_NULL.
everywhere s was set to S_NULL, prefix_char was initialized as NUL.
So checking for just one of them should be enough.
Again, I was a bit sleepy, maybe someone else would double check it :)
On Fri, May 23, 2008 at 3:12 PM, Joe Orton <jo...@redhat.com> wrote:
> 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
>
>
--
Lucian
Re: Warning in strings/apr_snprintf.c
Posted by Bojan Smojver <bo...@rexursive.com>.
On Fri, 2008-05-23 at 13:12 +0100, Joe Orton wrote:
> Interesting - is that gcc 4.3?
Yep, Fedora 9.
> 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?
Yes, it does.
--
Bojan
Re: Warning in strings/apr_snprintf.c
Posted by Joe Orton <jo...@redhat.com>.
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
Re: Warning in strings/apr_snprintf.c
Posted by Bojan Smojver <bo...@rexursive.com>.
On Wed, 2008-05-21 at 07:50 +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...
Ping...
--
Bojan