From 240ef8cd4e23bee7265594d2127c5723fa853a3c Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Mon, 21 Jan 2019 10:50:29 +0000 Subject: [PATCH] Handle another GCC compile-time warning. --- mingwrt/ChangeLog | 9 +++++++++ mingwrt/mingwex/memalign.c | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 31d9509..81a3946 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,12 @@ +2019-01-21 Keith Marshall + + Handle another GCC compile-time warning. + + * mingwex/memalign.c (is_power_of_two): Use in-line expansion... + (memalign_is_power_of_two): ...of this new function; this is required + to avoid -Wsequence-point warnings, which may arise when testing the + result of an assignment expression passed as the macro argument. + 2019-01-11 Keith Marshall Fix a mkstemp() file name generator defect. diff --git a/mingwrt/mingwex/memalign.c b/mingwrt/mingwex/memalign.c index 99adfa6..81af04e 100644 --- a/mingwrt/mingwex/memalign.c +++ b/mingwrt/mingwex/memalign.c @@ -9,7 +9,7 @@ * $Id$ * * Written by Keith Marshall - * Copyright (C) 2018, MinGW.org Project + * Copyright (C) 2018, 2019, MinGW.org Project * * Derived (with extensive modification) from, and replacing, the original * mingw-aligned-malloc.c implementation: @@ -68,7 +68,7 @@ * values, and bailing out, in the event of violation of this, or any other * parameter validation criterion. */ -#define is_power_of_two(x) (((x) > 0) && (((x) & ((x) - 1)) == 0)) +#define is_power_of_two(x) memalign_is_power_of_two((x)) #define error_return(c,r) {errno = (c); return (r);} /* We need "sizeof_ptr" to represent the smallest integer power of two @@ -120,6 +120,15 @@ void *__mingw_memalign_realloc( void *, struct memalign *, size_t ); * functions; (declare them as __CRT_ALIAS, to ensure that GCC will * always expand them in-line). */ +__CRT_ALIAS int memalign_is_power_of_two( int x ) +{ + /* This furnishes the implementation of the is_power_of_two() macro, + * as an in-line function expansion, to avoid GCC warnings which may + * arise as side effects of passing an assignment as macro parameter. + */ + return ((x > 0) && ((x & (x -1)) == 0)); +} + __CRT_ALIAS size_t memalign_min_alignment( void ) { /* This determines the size of a structure comprising a single byte -- 2.11.0