Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250930133331.GC1827@brightrain.aerifal.cx>
Date: Tue, 30 Sep 2025 09:33:31 -0400
From: Rich Felker <dalias@...c.org>
To: Qi.Chen@...driver.com
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] include/sched.h: fix _CPU_op_S to support
 expression such as '--i'

On Tue, Sep 30, 2025 at 06:17:18PM +0800, Qi.Chen@...driver.com wrote:
> From: Chen Qi <Qi.Chen@...driver.com>
> 
> We need a local variable to hold the result of (i). Otherwise,
> when this marco is as with expression such as '--i', we will
> get compilation error as below:
> 
>   error: operation on 'i' may be undefined [-Werror=sequence-point]
> 
> Signed-off-by: Chen Qi <Qi.Chen@...driver.com>
> ---
>  include/sched.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/sched.h b/include/sched.h
> index 8c3b53f0..e7b81ca1 100644
> --- a/include/sched.h
> +++ b/include/sched.h
> @@ -89,8 +89,8 @@ int sched_getcpu(void);
>  int sched_getaffinity(pid_t, size_t, cpu_set_t *);
>  int sched_setaffinity(pid_t, size_t, const cpu_set_t *);
>  
> -#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
> -	(((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) )
> +#define __CPU_op_S(i, size, set, op) ({size_t _i=(i); (_i)/8U >= (size) ? 0 : \
> +	(((unsigned long *)(set))[(_i)/8/sizeof(long)] op (1UL<<((_i)%(8*sizeof(long))))); })
>  
>  #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=)
>  #define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~)
> -- 
> 2.34.1

It is expected that interfaces that are specified to be macros may
evaluate their arguments more than once. Code that passes an
expression with side effects is erroneous.

We do not use GNUC statement-expressions or otherwise gratuitously
nonstandard things in the public headers, which are intended to work
with essentially any C compiler.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.