]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUILD: tree-wide: avoid warnings caused by redundant checks of obj_types
authorWilly Tarreau <w@1wt.eu>
Mon, 6 Dec 2021 07:01:02 +0000 (07:01 +0000)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Dec 2021 08:11:47 +0000 (09:11 +0100)
commit88bc800eae8d0a2118a273afc52ecdc529c9f523
tree9791be9e04be6fa553a3f0e9c9b38fe9a587579b
parent3010e00e1cc8388c2c01a43c597aa3ca07bff487
BUILD: tree-wide: avoid warnings caused by redundant checks of obj_types

At many places we use construct such as:

   if (objt_server(blah))
       do_something(objt_server(blah));

At -O2 the compiler manages to simplify the operation and see that the
second one returns the same result as the first one. But at -O1 that's
not always the case, and the compiler is able to emit a second
expression and sees the potential null that results from it, and may
warn about a potential null deref (e.g. with gcc-6.5). There are two
solutions to this:
  - either the result of the first test has to be passed to a local
    variable
  - or the second reference ought to be unchecked using the __objt_*
    variant.

This patch fixes all occurrences at once by taking the second approach
(the least intrusive). For constructs like:

   objt_server(blah) ? objt_server(blah)->name : "no name"

a macro could be useful. It would for example take the object type
(server), the field name (name) and the default value. But there
are probably not enough occurrences across the whole code for this
to really matter.

This should be backported wherever it applies.
src/backend.c
src/http_ana.c
src/proto_tcp.c
src/proto_uxst.c
src/stream.c
src/stream_interface.c