[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: func(va_arg_type, va_arg_type) segfault

From: Bruno Haible
Subject: Re: func(va_arg_type, va_arg_type) segfault
Date: Sun, 09 Feb 2020 11:43:37 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; )

> Is there a reason why this segfaults
>     va_start_void(alist);
>     myfunction(va_arg_uint(alist), va_arg_ptr(alist, void*));
>     va_return_void(alist);
> but this does not?
>     va_start_void(alist);
>     unsigned int i = va_arg_uint(alist);
>     void *p        = va_arg_ptr(alist, void*);
>     myfunction(i, p);
>     va_return_void(alist);

In the first case, you have undefined evaluation order [1]. Which
means that the compiler can decide to evaluate va_arg_ptr(alist, void*)
before va_arg_uint(alist) or - even worse - interleave the two
expressions, by pulling an 'unsigned int' and a 'void *' from
the same memory location and advancing to the next argument
twice afterwards.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]