Skip to content

Commit 5db304f

Browse files
committed
Fix the non-debug build in Groovy Gorilla (gcc 10.2)
The release build has been failing with the following error: ```shell FAILED: src/CMakeFiles/git2internal.dir/hash.c.o /usr/bin/cc -DHAVE_QSORT_R_GNU -DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\" -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\" -DSHA1DC_NO_STANDARD_INCLUDES=1 -D_FILE_OFFSET_BITS=64 -Isrc -I../src -I../include -I../deps/pcre -I../deps/http-parser -D_GNU_SOURCE -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer -Werror -Wall -Wextra -fvisibility= hidden -fPIC -Wno-documentation-deprecated-sync -Wno-missing-field-initializers -Wstrict-aliasing -Wstrict-prototypes -Wdeclaration-after-statement -Wshift-count-overflow -Wunused-const-variable -Wunused-function -Wint-conversion -Wformat -Wformat-security -Wmissing-declarations -g -D_DEBUG -O0 -std=gnu90 -MD -MT src/CMakeFiles/git2internal.dir/hash.c.o -MF s rc/CMakeFiles/git2internal.dir/hash.c.o.d -o src/CMakeFiles/git2internal.dir/hash.c.o -c ../src/hash.c ../src/hash.c: In function ‘git_hash_init’: ../src/hash.c:47:1: error: control reaches end of non-void function [-Werror=return-type] 47 | } | ^ ../src/hash.c: In function ‘git_hash_update’: ../src/hash.c:58:1: error: control reaches end of non-void function [-Werror=return-type] 58 | } | ^ ../src/hash.c: In function ‘git_hash_final’: ../src/hash.c:68:1: error: control reaches end of non-void function [-Werror=return-type] 68 | } | ^ ../src/hash.c: At top level: cc1: note: unrecognized command-line option ‘-Wno-documentation-deprecated-sync’ may have been intended to silence earlier diagnostics cc1: all warnings being treated as errors [11/533] Building C object src/CMakeFiles/git2internal.dir/odb_pack.c.o ninja: build stopped: subcommand failed. ``` The compiler _should_ be able to figure out that there is no way to reach the end of the non-void function since `GIT_ASSERT(0)` expands to either `assert()` or an unconditional `return -1;` (after doing constant folding and stuff, depending on the debug level). But it's not doing so at the moment, so let's help it.
1 parent 4fadd59 commit 5db304f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/hash.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ int git_hash_init(git_hash_ctx *ctx)
4141
case GIT_HASH_ALGO_SHA1:
4242
return git_hash_sha1_init(&ctx->sha1);
4343
default:
44-
GIT_ASSERT(0);
44+
/* unreachable */ ;
4545
}
46+
GIT_ASSERT(0);
47+
return -1;
4648
}
4749

4850
int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
@@ -51,8 +53,10 @@ int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
5153
case GIT_HASH_ALGO_SHA1:
5254
return git_hash_sha1_update(&ctx->sha1, data, len);
5355
default:
54-
GIT_ASSERT(0);
56+
/* unreachable */ ;
5557
}
58+
GIT_ASSERT(0);
59+
return -1;
5660
}
5761

5862
int git_hash_final(git_oid *out, git_hash_ctx *ctx)
@@ -61,8 +65,10 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
6165
case GIT_HASH_ALGO_SHA1:
6266
return git_hash_sha1_final(out, &ctx->sha1);
6367
default:
64-
GIT_ASSERT(0);
68+
/* unreachable */ ;
6569
}
70+
GIT_ASSERT(0);
71+
return -1;
6672
}
6773

6874
int git_hash_buf(git_oid *out, const void *data, size_t len)

0 commit comments

Comments
 (0)