From 59b6237135126e53690a41a2baba74c092304c21 Mon Sep 17 00:00:00 2001 From: Alan King Date: Thu, 19 Mar 2020 16:09:39 -0400 Subject: [PATCH] Fix GCC warnings preventing build -Wimplicit-fallthrough was added in newer versions of GCC. "// fall through" is a special tag for letting GCC know that a switch case fallthough is intentional. -Wformat-truncation was added in newer versions of GCC. Simply storing the return code of snprintf calls silences this. --- src/request.c | 14 +++++++++++--- src/util.c | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/request.c b/src/request.c index 800abde..187ef48 100644 --- a/src/request.c +++ b/src/request.c @@ -1632,17 +1632,25 @@ S3Status request_api_initialize(const char *userAgentInfo, int flags, char platform[96]; struct utsname utsn; + int snprintf_ret = 0; if (uname(&utsn)) { - snprintf(platform, sizeof(platform), "Unknown"); + snprintf_ret = snprintf(platform, sizeof(platform), "Unknown"); } else { - snprintf(platform, sizeof(platform), "%s%s%s", utsn.sysname, + snprintf_ret = snprintf(platform, sizeof(platform), "%s%s%s", utsn.sysname, utsn.machine[0] ? " " : "", utsn.machine); } - snprintf(userAgentG, sizeof(userAgentG), + if (snprintf_ret < 0) { + return S3StatusInternalError; + } + + snprintf_ret = snprintf(userAgentG, sizeof(userAgentG), "Mozilla/4.0 (Compatible; %s; libs3 %s.%s; %s)", userAgentInfo, LIBS3_VER_MAJOR, LIBS3_VER_MINOR, platform); + if (snprintf_ret < 0) { + return S3StatusInternalError; + } return S3StatusOK; } diff --git a/src/util.c b/src/util.c index ea787b9..de18eaa 100644 --- a/src/util.c +++ b/src/util.c @@ -485,16 +485,27 @@ uint64_t hash(const unsigned char *k, int length) switch(length) { case 12: c += ((uint32_t) k[11]) << 24; + // fall through case 11: c += ((uint32_t) k[10]) << 16; + // fall through case 10: c += ((uint32_t) k[9]) << 8; + // fall through case 9 : c += k[8]; + // fall through case 8 : b += ((uint32_t) k[7]) << 24; + // fall through case 7 : b += ((uint32_t) k[6]) << 16; + // fall through case 6 : b += ((uint32_t) k[5]) << 8; + // fall through case 5 : b += k[4]; + // fall through case 4 : a += ((uint32_t) k[3]) << 24; + // fall through case 3 : a += ((uint32_t) k[2]) << 16; + // fall through case 2 : a += ((uint32_t) k[1]) << 8; + // fall through case 1 : a += k[0]; break; case 0 : goto end; } @@ -525,16 +536,27 @@ uint64_t hash(const unsigned char *k, int length) switch(length) { case 12: c += k[11]; + // fall through case 11: c += ((uint32_t) k[10]) << 8; + // fall through case 10: c += ((uint32_t) k[9]) << 16; + // fall through case 9 : c += ((uint32_t) k[8]) << 24; + // fall through case 8 : b += k[7]; + // fall through case 7 : b += ((uint32_t) k[6]) << 8; + // fall through case 6 : b += ((uint32_t) k[5]) << 16; + // fall through case 5 : b += ((uint32_t) k[4]) << 24; + // fall through case 4 : a += k[3]; + // fall through case 3 : a += ((uint32_t) k[2]) << 8; + // fall through case 2 : a += ((uint32_t) k[1]) << 16; + // fall through case 1 : a += ((uint32_t) k[0]) << 24; break; case 0 : goto end; }