libglusterfs: prevent compile warnings with roof() and floor()

gcc 7 (default in Fedora 26) complains about the roof() and floor()
macros:

    stripe.c: In function 'stripe_truncate':
    stripe.c:701:49: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
         tmp_offset = roof(offset, fctx->stripe_size *
    ../../../../libglusterfs/src/common-utils.h:55:35: note: in definition of macro 'roof'
     #define roof(a,b) ((((a)+(b)-1)/((b)?(b):1))*(b))
                                       ^
    stripe.c:704:50: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
         tmp_offset = floor(offset, fctx->stripe_size *
    ../../../../libglusterfs/src/common-utils.h:56:28: note: in definition of macro 'floor'
     #define floor(a,b) (((a)/((b)?(b):1))*(b))
                                ^

The calculations done in stripe_truncate() look safe enough, but gcc
does not seem to like the passing the int/size_t to the `((b)?(b):1)`
compact if-statement, so use `b != 0` for the test.

Change-Id: If9fa4b8e86ba4b2ace61b1e05a5c28050fe4a7d3
Updates: #259
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: https://review.gluster.org/17842
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Raghavendra Talur <rtalur@redhat.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
This commit is contained in:
Niels de Vos 2017-07-20 16:59:32 +02:00
parent 6b89b8cee7
commit ed6efab247

View File

@ -52,8 +52,8 @@ void trap (void);
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define roof(a,b) ((((a)+(b)-1)/((b)?(b):1))*(b))
#define floor(a,b) (((a)/((b)?(b):1))*(b))
#define roof(a,b) ((((a)+(b)-1)/((b!=0)?(b):1))*(b))
#define floor(a,b) (((a)/((b!=0)?(b):1))*(b))
#define IPv4_ADDR_SIZE 32