]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: definitely silence some stupid GCC warnings
authorWilly Tarreau <w@1wt.eu>
Fri, 13 Dec 2013 14:14:55 +0000 (15:14 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 13 Dec 2013 14:21:36 +0000 (15:21 +0100)
It's becoming increasingly difficult to ignore unwanted function returns in
debug code with gcc. Now even when you try to work around it, it suggests a
way to write your code differently. For example :

    src/frontend.c:187:65: warning: if statement has empty body [-Wempty-body]
                if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
                                                                              ^
    src/frontend.c:187:65: note: put the semicolon on a separate line to silence this warning
    1 warning generated.

This is totally unacceptable, this code already had to be written this way
to shut it up in earlier versions. And now it comments the form ? What's the
purpose of the C language if you can't write anymore the code that does what
you want ?

Emeric proposed to just keep a global variable to drain such useless results
so that gcc stops complaining all the time it believes people who write code
are monkeys. The solution is acceptable because the useless assignment is done
only in debug code so it will not impact performance. This patch implements
this, until gcc becomes even "smarter" to detect that we tried to cheat.

include/common/standard.h
src/appsession.c
src/frontend.c
src/haproxy.c
src/proto_http.c
src/session.c

index be0762573d9c5575bc4256e4ba8ff0af3ef83280..c4c5d64f175a74d4031b2f9886a63e03172e033b 100644 (file)
@@ -760,6 +760,19 @@ char *env_expand(char *in);
  */
 #define fddebug(msg...) do { char *_m = NULL; memprintf(&_m, ##msg); if (_m) write(-1, _m, strlen(_m)); free(_m); } while (0)
 
+/* used from everywhere just to drain results we don't want to read and which
+ * recent versions of gcc increasingly and annoyingly complain about.
+ */
+extern int shut_your_big_mouth_gcc_int;
+
+/* used from everywhere just to drain results we don't want to read and which
+ * recent versions of gcc increasingly and annoyingly complain about.
+ */
+static inline void shut_your_big_mouth_gcc(int r)
+{
+       shut_your_big_mouth_gcc_int = r;
+}
+
 /* same as strstr() but case-insensitive */
 const char *strnistr(const char *str1, int len_str1, const char *str2, int len_str2);
 
index a71f186c8ea9eac8b165cb21cbec1c570553aef3..c22be45ce69f2e1c3afb5e0012901337930f5eba 100644 (file)
@@ -99,7 +99,7 @@ static struct task *appsession_refresh(struct task *t)
                                            (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
                                                chunk_printf(&trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n", 
                                                             element->sessid, element->serverid?element->serverid:"(null)");
-                                               if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
+                                               shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
                                        }
                                        /* delete the expired element from within the hash table */
                                        LIST_DEL(&element->hash_list);
index 8a01a4ab999c0d9e46b8d20ca67b2de65e3bc551..591c1f21ad89ac5f40624602fe418adf8be6cd22 100644 (file)
@@ -184,7 +184,7 @@ int frontend_accept(struct session *s)
                        break;
                }
 
-               if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
+               shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
        }
 
        if (s->fe->mode == PR_MODE_HTTP)
index 0ec217e534b2aeda41494a82a9dbd21b46b1ee3a..5cfebd29a05dc5b8b89e0bd9f3937f629310112e 100644 (file)
@@ -193,6 +193,11 @@ const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
 char hostname[MAX_HOSTNAME_LEN];
 char localpeer[MAX_HOSTNAME_LEN];
 
+/* used from everywhere just to drain results we don't want to read and which
+ * recent versions of gcc increasingly and annoyingly complain about.
+ */
+int shut_your_big_mouth_gcc_int = 0;
+
 /* list of the temporarily limited listeners because of lack of resource */
 struct list global_listener_queue = LIST_HEAD_INIT(global_listener_queue);
 struct task *global_listener_queue_task;
@@ -1541,7 +1546,7 @@ int main(int argc, char **argv)
                        if (pidfd >= 0) {
                                char pidstr[100];
                                snprintf(pidstr, sizeof(pidstr), "%d\n", ret);
-                               if (write(pidfd, pidstr, strlen(pidstr)) < 0) /* shut gcc warning */;
+                               shut_your_big_mouth_gcc(write(pidfd, pidstr, strlen(pidstr)));
                        }
                        relative_pid++; /* each child will get a different one */
                }
index b7982bce3100268cd7063c9a368842e3344c0325..db6a88700af11841f04adbe349bb41896b8e1de3 100644 (file)
@@ -7992,7 +7992,7 @@ void debug_hdr(const char *dir, struct session *t, const char *start, const char
        UBOUND(max, trash.size - trash.len - 3);
        trash.len += strlcpy2(trash.str + trash.len, start, max + 1);
        trash.str[trash.len++] = '\n';
-       if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
+       shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
 }
 
 /*
index 86dcb848420701b77b14a3a19e6711742d5f2f50..21fea399d99fba10a8c892f49355532c19a0f495 100644 (file)
@@ -2359,7 +2359,7 @@ struct task *process_session(struct task *t)
                                      s->uniq_id, s->be->id,
                                      objt_conn(s->si[0].end) ? (unsigned short)objt_conn(s->si[0].end)->t.sock.fd : -1,
                                      objt_conn(s->si[1].end) ? (unsigned short)objt_conn(s->si[1].end)->t.sock.fd : -1);
-                       if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
+                       shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
                }
 
                if (s->si[0].state == SI_ST_CLO &&
@@ -2368,7 +2368,7 @@ struct task *process_session(struct task *t)
                                      s->uniq_id, s->be->id,
                                      objt_conn(s->si[0].end) ? (unsigned short)objt_conn(s->si[0].end)->t.sock.fd : -1,
                                      objt_conn(s->si[1].end) ? (unsigned short)objt_conn(s->si[1].end)->t.sock.fd : -1);
-                       if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
+                       shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
                }
        }
 
@@ -2473,7 +2473,7 @@ struct task *process_session(struct task *t)
                              s->uniq_id, s->be->id,
                              objt_conn(s->si[0].end) ? (unsigned short)objt_conn(s->si[0].end)->t.sock.fd : -1,
                              objt_conn(s->si[1].end) ? (unsigned short)objt_conn(s->si[1].end)->t.sock.fd : -1);
-               if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
+               shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
        }
 
        s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);