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

Arguments to calloc are reversed #100

Open
WebbyMD1 opened this issue Nov 27, 2024 · 0 comments
Open

Arguments to calloc are reversed #100

WebbyMD1 opened this issue Nov 27, 2024 · 0 comments

Comments

@WebbyMD1
Copy link

WebbyMD1 commented Nov 27, 2024

Building libcli with GCC 14 or newer fails. It seems that some (but not all) calls to calloc are done with the size of a struct as the first parameter and the second parameter the number of those objects to allocate memory for. The call to calloc is the reverse of this. Gcc is now checking for this error (-Werror=calloc-transposed-args) and because it is detecting the parameters swapped the build fails. I have found this on an Ubunut 24.10 machine, with GCC 14.2.0 and the current head of the stable branch. The errors reported by GCC are as below:

gcc -g -O3 -Wall -std=c99 -pedantic -Wformat-security -Wno-format-zero-length -Werror -Wwrite-strings -Wformat -fdiagnostics-show-option -Wextra -Wsign-compare -Wcast-align -Wno-unused-parameter -fPIC -o libcli.o -c libcli.c
libcli.c: In function ‘cli_register_command’:
libcli.c:430:27: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
430 | if (!(c = calloc(sizeof(struct cli_command), 1))) return NULL;
| ^~~~~~
libcli.c:430:27: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_init’:
libcli.c:600:29: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
600 | if (!(cli = calloc(sizeof(struct cli_def), 1))) return 0;
| ^~~~~~
libcli.c:600:29: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_match_filter_init’:
libcli.c:1960:38: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
1960 | filt->data = state = calloc(sizeof(struct cli_match_filter_state), 1);
| ^~~~~~
libcli.c:1960:38: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_range_filter_init’:
libcli.c:2053:38: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
2053 | filt->data = state = calloc(sizeof(struct cli_range_filter_state), 1);
| ^~~~~~
libcli.c:2053:38: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_count_filter_init’:
libcli.c:2090:36: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
2090 | if (!(filt->data = calloc(sizeof(int), 1))) return CLI_ERROR;
| ^~~
libcli.c:2090:36: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_register_filter’:
libcli.c:2147:27: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
2147 | if (!(c = calloc(sizeof(struct cli_command), 1))) return NULL;
| ^~~~~~
libcli.c:2147:27: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_register_optarg’:
libcli.c:2259:32: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
2259 | if (!(optarg = calloc(sizeof(struct cli_optarg), 1))) goto CLEANUP;
| ^~~~~~
libcli.c:2259:32: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_int_register_buildmode_command’:
libcli.c:2535:27: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
2535 | if (!(c = calloc(sizeof(struct cli_command), 1))) return NULL;
| ^~~~~~
libcli.c:2535:27: note: earlier argument should specify number of elements, later size of each element
libcli.c: In function ‘cli_int_execute_pipeline’:
libcli.c:3098:27: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
3098 | *filt = calloc(sizeof(struct cli_filter), 1);
| ^~~~~~
libcli.c:3098:27: note: earlier argument should specify number of elements, later size of each element
cc1: all warnings being treated as errors
make: *** [Makefile:53: libcli.o] Error 1

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

No branches or pull requests

1 participant