]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: state-file: make the path concatenation code a bit more consistent
authorWilly Tarreau <w@1wt.eu>
Tue, 16 Oct 2018 17:26:12 +0000 (19:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Oct 2018 17:26:12 +0000 (19:26 +0200)
There are as many ways to build the globalfilepathlen variable as branches
in the if/then/else, creating lots of confusion. Address the most obvious
parts, but some polishing definitely is still needed.

src/server.c

index 9a0392084fbb18eee301ae7c2c8797dfc6877b4e..c0122b6689f2d8015735ca2c6da80edf4d919d57 100644 (file)
@@ -3164,14 +3164,13 @@ void apply_server_state(void)
                }
                else if (global.server_state_base) {
                        len = strlen(global.server_state_base);
-                       globalfilepathlen += len;
-
-                       if (globalfilepathlen > MAXPATHLEN) {
+                       if (len > MAXPATHLEN) {
                                globalfilepathlen = 0;
                                goto globalfileerror;
                        }
                        memcpy(globalfilepath, global.server_state_base, len);
-                       globalfilepath[globalfilepathlen] = 0;
+                       globalfilepath[len] = 0;
+                       globalfilepathlen = len;
 
                        /* append a slash if needed */
                        if (!globalfilepathlen || globalfilepath[globalfilepathlen - 1] != '/') {