You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to build readsb-protobuf with GCC 14.2.1 currently results in the following error:
$ make
[...]
gcc -DMODES_READSB_VERSION=\"'v4.0.4'\" -DMODES_READSB_VARIANT=\"Mictronics\" -D_GNU_SOURCE -std=c11 -O2 -g -W -D_DEFAULT_SOURCE -Wall -Werror -fno-common -Wmissing-declarations -c net_io.c -o net_io.o
net_io.c: In function ‘serviceInit’:
net_io.c:116:35: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
116 | if (!(service = calloc(sizeof (*service), 1))) {
| ^
net_io.c:116:35: note: earlier argument should specify number of elements, later size of each element
[...]
The reason is a transposed argument in the call to calloc at line 116 of net_io.c. The first argument should be the number of members, and the second one their individual size. This error is now picked up by GCC 14 and warnings are treated as errors per -Werror.
Reproduction
Clone the repository on a system with GCC 14.2.1.
Get inside of the directory
make
Background
This repository is currently pointed to by Archlinux User Repository's readsb-git package. Attempting to build it on an up-to-date installation of ArchLinux, however, fails.
Installing gcc version 13 on ArchLinux via the extra/gcc13 package, and exporting CC with value gcc13 fixes the build problem.
Solutions
Either one of these:
Change calloc argument order and preserve zero-intialization of memory
diff --git a/net_io.c b/net_io.c
index 167b876e..34502f3f 100644
--- a/net_io.c+++ b/net_io.c@@ -113,7 +113,7 @@ struct net_service *serviceInit(const char *descr, struct net_writer *writer, he
exit(1);
}
- if (!(service = calloc(sizeof (*service), 1))) {+ if (!(service = calloc(1, sizeof (*service)))) {
fprintf(stderr, "Out of memory allocating service %s\n", descr);
exit(1);
}
Don't use calloc if you don't actually care about zero-initializing memory)
diff --git a/net_io.c b/net_io.c
index 167b876e..69815cd9 100644
--- a/net_io.c+++ b/net_io.c@@ -113,7 +113,7 @@ struct net_service *serviceInit(const char *descr, struct net_writer *writer, he
exit(1);
}
- if (!(service = calloc(sizeof (*service), 1))) {+ if (!(service = malloc(sizeof (*service)))) {
fprintf(stderr, "Out of memory allocating service %s\n", descr);
exit(1);
}
i could open a PR but for such a minimal change it feels overkill.
Cheers
The text was updated successfully, but these errors were encountered:
Hi,
Attempting to build
readsb-protobuf
with GCC 14.2.1 currently results in the following error:The reason is a transposed argument in the call to
calloc
at line 116 ofnet_io.c
. The first argument should be the number of members, and the second one their individual size. This error is now picked up by GCC 14 and warnings are treated as errors per-Werror
.Reproduction
make
Background
This repository is currently pointed to by Archlinux User Repository's
readsb-git
package. Attempting to build it on an up-to-date installation of ArchLinux, however, fails.Installing
gcc
version 13 on ArchLinux via theextra/gcc13
package, and exportingCC
with valuegcc13
fixes the build problem.Solutions
Either one of these:
calloc
argument order and preserve zero-intialization of memorycalloc
if you don't actually care about zero-initializing memory)i could open a PR but for such a minimal change it feels overkill.
Cheers
The text was updated successfully, but these errors were encountered: