]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: h1: silence an initiialized warning with gcc-4.7 and -Os
authorWilly Tarreau <w@1wt.eu>
Tue, 4 Oct 2022 06:02:03 +0000 (08:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 4 Oct 2022 06:02:03 +0000 (08:02 +0200)
Building h1.c with gcc-4.7 -Os produces the following warning:

  src/h1.c: In function 'h1_headers_to_hdr_list':
  src/h1.c:1101:36: warning: 'ptr' may be used uninitialized in this function [-Wmaybe-uninitialized]

In fact ptr may be taken from sl.rq.u.ptr which is only initialized after
passing through the relevant states, but gcc doesn't know which states
are visited. Adding an ALREADY_CHECKED() statement there is sufficient to
shut it up and doesn't affect the emitted code.

This may be backported to stable versions to make sure that builds on older
distros and systems is clean.

src/h1.c

index 81445cefa4cf5e20edf3e639149669e2efd29b02..cce484ca4b0cdf3ab3d96a56881dd629c6601855 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1013,6 +1013,11 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                                if (ret < 0) {
                                        if (h1m->err_pos < -1) {
                                                state = H1_MSG_LAST_LF;
+                                               /* WT: gcc seems to see a path where sl.rq.u.ptr was used
+                                                * uninitialized, but it doesn't know that the function is
+                                                * called with initial states making this impossible.
+                                                */
+                                               ALREADY_CHECKED(sl.rq.u.ptr);
                                                ptr = ((ret == -1) ? sl.rq.u.ptr : host->ptr); /* Set ptr on the error */
                                                goto http_msg_invalid;
                                        }