[PATCH] fix -Wsign-conversion warning with gcc 8.2

Maxim Dounin mdounin at mdounin.ru
Fri May 27 02:42:05 UTC 2022


Hello!

On Thu, May 26, 2022 at 02:42:14PM -0700, Andres Beltran wrote:

> Gently ping on this patch. Any comments?
> 
> On 3/14/2022 4:42 PM, Sinan Kaya wrote:
> 
>  > # HG changeset patch
>  > # User Sinan Kaya <sinan.kaya at microsoft.com>
>  > # Date 1647289518 14400
>  > #      Mon Mar 14 16:25:18 2022 -0400
>  > # Node ID f22520b612969dbfa17205129510927519370000
>  > # Parent  a736a7a613ea6e182ff86fbadcb98bb0f8891c0b
>  > fix -Wsign-conversion warning with gcc 8.2
>  >
>  > Getting compiler warning with -Wsign-conversion.
>  >
>  > /usr/include/nginx/core/ngx_crc32.h:31:47: warning: conversion to
>  > 'uint32_t' {aka 'unsigned int'} from 'int' may change the sign of the
>  > result [-Wsign-conversion]
>  >    31 |         crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^
>  > (crc >> 4);
>  >
>  > diff -r a736a7a613ea -r f22520b61296 src/core/ngx_crc32.h
>  > --- a/src/core/ngx_crc32.h    Tue Feb 08 17:35:27 2022 +0300
>  > +++ b/src/core/ngx_crc32.h    Mon Mar 14 16:25:18 2022 -0400
>  > @@ -28,7 +28,8 @@
>  >      while (len--) {
>  >          c = *p++;
>  >          crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >>
>  > 4);
>  > -        crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc 
>  >> 4);
>  > +        crc = ngx_crc32_table_short[(crc ^ (u_char)(c >> 4)) & 0xf];
>  > +        crc = crc ^ (crc >> 4);
>  >      }
>  >
>  >      return crc ^ 0xffffffff;

Trying to compile nginx with -Wsign-conversion produces a lot more 
than this specific (mis)warning.  For more or less obvious reasons 
there are no plans to silence them: this is going to be a large 
work which is highly unlikely to catch any real bugs, yet will 
result in a lot of garbage in the code.

If for some reason you think this particular warning should be 
silenced, you may want to elaborate more on your reasons.

Hope this helps.

-- 
Maxim Dounin
http://mdounin.ru/



More information about the nginx-devel mailing list