Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC15(-std=gnu23) adjustment: Fix function pointer cast in qsort() #665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

charmitro
Copy link
Contributor

@charmitro charmitro commented Nov 19, 2024

1. Suppress -Wold-style-definition warnings globally since we prefer old-style definitions.
2. Fix hlink.c's cast in qsort() call to properly declare type.
3. Fix pool_alloc.c's function pointer type to match its usage.
4. Fix syscall.c's lseek64 forward declarations.
5. Fix bool typedef conflict in wildtest.c by renaming to rsync_bool.

This cleans up the build with modern compilers (GCC15) while maintaining compatibility with older versions. The qsort comparison function cast in particular is now more type-safe.

Closes #664

Replace unsafe generic function pointer cast with proper type cast for
qsort() comparison function. This fixes a potential type mismatch
warning without changing the behavior.

Signed-off-by: Charalampos Mitrodimas <[email protected]>
@charmitro charmitro changed the title GCC15(-std=gnu23) adjustments GCC15(-std=gnu23) adjustment: Fix function pointer cast in qsort() Nov 20, 2024
@charmitro
Copy link
Contributor Author

PR updated to only fix a pointer cast in qsort() in hlink.c:

rsync/hlink.c

Line 120 in 321dd78

qsort(ndx_list, ndx_count, sizeof ndx_list[0], (int (*)()) hlink_compare_gnum);

hlink.c: In function ‘match_gnums’:
hlink.c:120:56: warning: cast between incompatible function types from ‘int (*)(int *, int *)’ to ‘int (*)(void)’ [-Wcast-function-type]
  120 |         qsort(ndx_list, ndx_count, sizeof ndx_list[0], (int (*)()) hlink_compare_gnum);
      |                                                        ^
hlink.c:120:56: error: passing argument 4 of ‘qsort’ from incompatible pointer type [-Wincompatible-pointer-types]
  120 |         qsort(ndx_list, ndx_count, sizeof ndx_list[0], (int (*)()) hlink_compare_gnum);
      |                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                        |
      |                                                        int (*)(void)
In file included from rsync.h:328,
                 from hlink.c:23:
/usr/include/stdlib.h:971:34: note: expected ‘__compar_fn_t’ {aka ‘int (*)(const void *, const void *)’} but argument is of type ‘int (*)(void)’
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure with GCC 15 (C23)
2 participants