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>
Fri, 24 Dec 2021 16:57:07 +0000 (17:57 +0100)
commitd1b5cf3f37e653f59d5e86c394d40cd5fa3b8c5d
tree77c9e9e90a344273f3284a8821f81ee4aa263973
parented4f13530956b94b8fc4cf22b9655c8189fa34d8
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.

(cherry picked from commit 88bc800eae8d0a2118a273afc52ecdc529c9f523)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit dcb4fad90b42b94a156e4999d2452350175ea1d5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 661825922df5d18e692e3689973c79350c07fa8f)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/backend.c
src/http_ana.c
src/proto_tcp.c
src/proto_uxst.c
src/stream.c
src/stream_interface.c