CLEANUP: state-file: make the path concatenation code a bit more consistent

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.
This commit is contained in:
Willy Tarreau 2018-10-16 19:26:12 +02:00
parent 17f8b90736
commit 5dfb6c4cc9

View File

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