From: Junio C Hamano Date: Mon, 23 Dec 2024 17:32:10 +0000 (-0800) Subject: Merge branch 'ps/build-sign-compare' X-Git-Tag: v2.48.0-rc1~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4156b6a741c7fb15a4eccb320612fb6e453f439c;p=thirdparty%2Fgit.git Merge branch 'ps/build-sign-compare' Start working to make the codebase buildable with -Wsign-compare. * ps/build-sign-compare: t/helper: don't depend on implicit wraparound scalar: address -Wsign-compare warnings builtin/patch-id: fix type of `get_one_patchid()` builtin/blame: fix type of `length` variable when emitting object ID gpg-interface: address -Wsign-comparison warnings daemon: fix type of `max_connections` daemon: fix loops that have mismatching integer types global: trivial conversions to fix `-Wsign-compare` warnings pkt-line: fix -Wsign-compare warning on 32 bit platform csum-file: fix -Wsign-compare warning on 32-bit platform diff.h: fix index used to loop through unsigned integer config.mak.dev: drop `-Wno-sign-compare` global: mark code units that generate warnings with `-Wsign-compare` compat/win32: fix -Wsign-compare warning in "wWinMain()" compat/regex: explicitly ignore "-Wsign-compare" warnings git-compat-util: introduce macros to disable "-Wsign-compare" warnings --- 4156b6a741c7fb15a4eccb320612fb6e453f439c diff --cc midx-write.c index bcd1d50eb0,f1a6f83bae..0066594fa6 --- a/midx-write.c +++ b/midx-write.c @@@ -1,3 -1,6 +1,5 @@@ -#define USE_THE_REPOSITORY_VARIABLE + #define DISABLE_SIGN_COMPARE_WARNINGS + #include "git-compat-util.h" #include "abspath.h" #include "config.h" diff --cc midx.c index e0eae1c25e,504e03327a..f8a75cafd4 --- a/midx.c +++ b/midx.c @@@ -1,3 -1,6 +1,5 @@@ -#define USE_THE_REPOSITORY_VARIABLE + #define DISABLE_SIGN_COMPARE_WARNINGS + #include "git-compat-util.h" #include "config.h" #include "dir.h" diff --cc oss-fuzz/fuzz-parse-attr-line.c index 45a4c4e53c,0000000000..e0e4bc6358 mode 100644,000000..100644 --- a/oss-fuzz/fuzz-parse-attr-line.c +++ b/oss-fuzz/fuzz-parse-attr-line.c @@@ -1,39 -1,0 +1,41 @@@ ++#define DISABLE_SIGN_COMPARE_WARNINGS ++ +#include "git-compat-util.h" +#include +#include +#include +#include +#include "attr.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + struct match_attr *res; + char *buf; + + buf = malloc(size + 1); + if (!buf) + return 0; + + memcpy(buf, data, size); + buf[size] = 0; + + res = parse_attr_line(buf, "dummy", 0, 0); + + if (res) { + int j; + for (j = 0; j < res->num_attr; j++) { + const char *setto = res->state[j].setto; + if (ATTR_TRUE(setto) || ATTR_FALSE(setto) || + ATTR_UNSET(setto)) + ; + else + free((char *)setto); + } + free(res); + } + free(buf); + + return 0; +} diff --cc pack-bitmap.c index 7aa2410d9b,bbcf7e9401..bceb6da042 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@@ -1,3 -1,6 +1,5 @@@ -#define USE_THE_REPOSITORY_VARIABLE + #define DISABLE_SIGN_COMPARE_WARNINGS + #include "git-compat-util.h" #include "commit.h" #include "gettext.h" diff --cc packfile.c index 9c4bd81a8c,f38c207fb6..cc7ab6403a --- a/packfile.c +++ b/packfile.c @@@ -1,3 -1,5 +1,4 @@@ -#define USE_THE_REPOSITORY_VARIABLE + #define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h" #include "environment.h" diff --cc reftable/system.h index 7d5f803eeb,d3b8a55f4b..5274eca1d0 --- a/reftable/system.h +++ b/reftable/system.h @@@ -11,91 -11,14 +11,93 @@@ https://developers.google.com/open-sour /* This header glues the reftable library to the rest of Git */ + #define DISABLE_SIGN_COMPARE_WARNINGS + #include "git-compat-util.h" -#include "lockfile.h" -#include "tempfile.h" -#include "hash.h" /* hash ID, sizes.*/ -#include "dir.h" /* remove_dir_recursively, for tests.*/ -int hash_size(uint32_t id); +/* + * An implementation-specific temporary file. By making this specific to the + * implementation it becomes possible to tie temporary files into any kind of + * signal or atexit handlers for cleanup on abnormal situations. + */ +struct reftable_tmpfile { + const char *path; + int fd; + void *priv; +}; +#define REFTABLE_TMPFILE_INIT ((struct reftable_tmpfile) { .fd = -1, }) + +/* + * Create a temporary file from a pattern similar to how mkstemp(3p) would. + * The `pattern` shall not be modified. On success, the structure at `out` has + * been initialized such that it is ready for use. Returns 0 on success, a + * reftable error code on error. + */ +int tmpfile_from_pattern(struct reftable_tmpfile *out, const char *pattern); + +/* + * Close the temporary file's file descriptor without removing the file itself. + * This is a no-op in case the file has already been closed beforehand. Returns + * 0 on success, a reftable error code on error. + */ +int tmpfile_close(struct reftable_tmpfile *t); + +/* + * Close the temporary file and delete it. This is a no-op in case the file has + * already been deleted or renamed beforehand. Returns 0 on success, a reftable + * error code on error. + */ +int tmpfile_delete(struct reftable_tmpfile *t); + +/* + * Rename the temporary file to the provided path. The temporary file must be + * active. Return 0 on success, a reftable error code on error. Deactivates the + * temporary file. + */ +int tmpfile_rename(struct reftable_tmpfile *t, const char *path); + +/* + * An implementation-specific file lock. Same as with `reftable_tmpfile`, + * making this specific to the implementation makes it possible to tie this + * into signal or atexit handlers such that we know to clean up stale locks on + * abnormal exits. + */ +struct reftable_flock { + const char *path; + int fd; + void *priv; +}; +#define REFTABLE_FLOCK_INIT ((struct reftable_flock){ .fd = -1, }) + +/* + * Acquire the lock for the given target path by exclusively creating a file + * with ".lock" appended to it. If that lock exists, we wait up to `timeout_ms` + * to acquire the lock. If `timeout_ms` is 0 we don't wait, if it is negative + * we block indefinitely. + * + * Retrun 0 on success, a reftable error code on error. + */ +int flock_acquire(struct reftable_flock *l, const char *target_path, + long timeout_ms); + +/* + * Close the lockfile's file descriptor without removing the lock itself. This + * is a no-op in case the lockfile has already been closed beforehand. Returns + * 0 on success, a reftable error code on error. + */ +int flock_close(struct reftable_flock *l); + +/* + * Release the lock by unlinking the lockfile. This is a no-op in case the + * lockfile has already been released or committed beforehand. Returns 0 on + * success, a reftable error code on error. + */ +int flock_release(struct reftable_flock *l); + +/* + * Commit the lock by renaming the lockfile into place. Returns 0 on success, a + * reftable error code on error. + */ +int flock_commit(struct reftable_flock *l); #endif diff --cc t/unit-tests/t-reftable-stack.c index e208e156f0,4377c0af1b..aeec195b2b --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@@ -6,9 -6,10 +6,11 @@@ license that can be found in the LICENS https://developers.google.com/open-source/licenses/bsd */ + #define DISABLE_SIGN_COMPARE_WARNINGS + #include "test-lib.h" #include "lib-reftable.h" +#include "dir.h" #include "reftable/merged.h" #include "reftable/reader.h" #include "reftable/reftable-error.h"