]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: threads: fix multiple use of argument inside HA_ATOMIC_CAS()
authorWilly Tarreau <w@1wt.eu>
Tue, 5 May 2020 13:58:00 +0000 (15:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 May 2020 14:05:45 +0000 (16:05 +0200)
commitd66345d6b0639dfc42986a4326e6f6f6d18e053e
treef7065500838652638b97899efd5e5de7c31aecae
parent0e9d87bf0676a0813cef6cb0c85e74e5707cff7d
BUG/MINOR: threads: fix multiple use of argument inside HA_ATOMIC_CAS()

When threads are disabled, HA_ATOMIC_CAS() becomes a simple compound
expression. However this expression presents a problem, which is that
its arguments are evaluated multiple times, once for the comparison
and once again for the assignement. This presents a risk of performing
some side-effect operations twice in the non-threaded case (e.g. in
case of auto-increment or function return).

The macro was rewritten using local copies for arguments like the
other macros do.

Fortunately a complete inspection of the code indicates that this case
currently never happens. It was however responsible for the strict-aliasing
warning emitted when building fd.c without threads but with 64-bit CAS.

This may be backported as far as 1.8 though it will not fix any existing
bug and is more of a long-term safety measure in case a future fix would
depend on this behavior.
include/common/hathreads.h