Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix GCC warnings preventing build
Browse files Browse the repository at this point in the history
-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.
  • Loading branch information
alanking authored and trel committed Mar 23, 2020
1 parent 0f5c603 commit 59b6237
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 59b6237

Please sign in to comment.