1
0
mirror of https://github.com/git/git.git synced 2024-10-18 19:20:43 +02:00
git/compat
Jeff King beaa1d952b hashmap: use expected signatures for comparison functions
We prefer for callback functions to match the signature with which
they'll be called, rather than casting them to the correct type when
assigning function pointers. Even though casting often works in the real
world, it is a violation of the standard.

We did a mass conversion in 939af16eac (hashmap_cmp_fn takes
hashmap_entry params, 2019-10-06), but have grown a few new cases since
then. Because of the cast, the compiler does not complain. However, as
of clang-18, UBSan will catch these at run-time, and the case in
range-diff.c triggers when running t3206.

After seeing that one, I scanned the results of:

  git grep '_fn)[^(]' '*.c' | grep -v typedef

and found a similar case in compat/terminal.c (which presumably isn't
called in the test suite, since it doesn't trigger UBSan). There might
be other cases lurking if the cast is done using a typedef that doesn't
end in "_fn", but loosening it finds too many false positives. I also
looked for:

  git grep ' = ([a-z_]*) *[a-z]' '*.c'

to find assignments that cast, but nothing looked like a function.

The resulting code is unfortunately a little longer, but the bonus of
using container_of() is that we are no longer restricted to the
hashmap_entry being at the start of the struct.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-08-19 21:17:53 -07:00
..
fsmonitor fsmonitor-ll.h: split this header out of fsmonitor.h 2023-06-21 13:39:54 -07:00
linux
nedmalloc
poll
regex
simple-ipc cache.h: remove this no-longer-used header 2023-06-21 13:39:53 -07:00
stub
vcbuild
win32 Merge branch 'ds/maintenance-on-windows-fix' 2023-08-15 10:19:47 -07:00
.gitattributes
access.c
apple-common-crypto.h
basename.c
bswap.h
compiler.h
disk.h abspath.h: move absolute path functions from cache.h 2023-03-21 10:56:52 -07:00
fileno.c
fopen.c
hstrerror.c
inet_ntop.c
inet_pton.c
memmem.c
mingw.c Merge branch 'ma/locate-in-path-for-windows' 2023-08-09 16:18:16 -07:00
mingw.h Merge branch 'ma/locate-in-path-for-windows' 2023-08-09 16:18:16 -07:00
mkdir.c
mkdtemp.c
mmap.c
msvc.c
msvc.h
nonblock.c
nonblock.h
obstack.c
obstack.h
open.c
pread.c treewide: remove double forward declaration of read_in_full 2023-04-11 08:52:11 -07:00
precompose_utf8.c cache.h: remove this no-longer-used header 2023-06-21 13:39:53 -07:00
precompose_utf8.h
qsort_s.c
regcomp_enhanced.c
setenv.c
sha1-chunked.c cache.h: remove this no-longer-used header 2023-06-21 13:39:53 -07:00
sha1-chunked.h
snprintf.c
stat.c
strcasestr.c
strdup.c
strlcpy.c
strtoimax.c
strtoumax.c
terminal.c hashmap: use expected signatures for comparison functions 2023-08-19 21:17:53 -07:00
terminal.h
unsetenv.c
win32.h
win32mmap.c
winansi.c
zlib-uncompress2.c