Closed mbooth101 closed 2 months ago
I am locally appling a patch like this:
From a6b6d2d7cfd9774220ccd00d031e2f699afd3d29 Mon Sep 17 00:00:00 2001
From: Mat Booth <mat.booth@gmail.com>
Date: Sun, 17 Mar 2024 15:32:40 +0000
Subject: [PATCH] Fix compilation errors caused by GCC 14
---
.../src/CMakeLists.txt | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/FTL-abcbcc58f5a63c21a11a4af2f0d5a664aa11ecfa/src/CMakeLists.txt b/FTL-abcbcc58f5a63c21a11a4af2f0d5a664aa11ecfa/src/CMakeLists.txt
index 185ba5d..f689760 100644
--- a/FTL-abcbcc58f5a63c21a11a4af2f0d5a664aa11ecfa/src/CMakeLists.txt
+++ b/FTL-abcbcc58f5a63c21a11a4af2f0d5a664aa11ecfa/src/CMakeLists.txt
@@ -155,11 +155,22 @@ else()
set(EXTRAWARN_GCC13 "")
endif()
+# Extra warnings flags available only in GCC 14 and higher
+# In GCC 14, -Wextra implies -Wcalloc-transposed-args however, there is
+# nothing wrong with the calls to calloc that it detects, so disable
+# that warning here
+if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_C_COMPILER_VERSION VERSION_GREATER 14)
+set(EXTRAWARN_GCC14 "-Wno-calloc-transposed-args")
+else()
+set(EXTRAWARN_GCC14 "")
+endif()
+
set(EXTRAWARN "${EXTRAWARN_GCC6} \
${EXTRAWARN_GCC7} \
${EXTRAWARN_GCC8} \
${EXTRAWARN_GCC12} \
- ${EXTRAWARN_GCC13}")
+ ${EXTRAWARN_GCC13} \
+ ${EXTRAWARN_GCC14}")
# Remove extra spaces from EXTRAWARN
string(REGEX REPLACE " +" " " EXTRAWARN "${EXTRAWARN}")
--
2.41.0
Thanks for your comments, I haven't tried building on such a recent GCC version myself. I'm actually torn about the solution you suggest - yes, sure, there isn't anything wrong with our code. The warning wants to ensure we are using calloc()
as it was designed and that means the first argument is nmem
and the second size
. Even when it makes no functional difference, one could also argument that the "real" fix would be
-cap_user_header_t hdr = calloc(sizeof(*hdr), capsize);
+cap_user_header_t hdr = calloc(capsize, sizeof(*hdr));
What do you think? I'm always trying to try to comply with compiler warnings whenever possible (and meaningful). It seems meaningful here because (warning: rusty partially unreliable memory excerpt ahead!) I recall that calloc
may be implemented in a way that ensures alignment matching the size
parameter. So the order of the arguments can actually make a difference and the mere fact that someone did the work adding warning rules to GCC 14 (combined with that this has been accepted) tells me that there are good reasons to use the function as defined :-)
I am happy to see it fixed in any manner you think is best -- I am not a GCC expert, nor am I a FTL expert -- but your fix may indeed be better if only because not disabling the warning would prevent more infractions from sneaking into the code base. :-)
You could test swapping the arguments locally to see if anything else comes up. As GCC 14 has not even been officially released, I'm a bit hesitant to invest time into creating/installing a full testing environment yet. We may simply wait for alpine:edge
to eventually pick it up once finalized.
This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.
This issue has been mentioned on Pi-hole Userspace. There might be relevant details there:
https://discourse.pi-hole.net/t/certificate-domain-mismatch-warning-behind-reverse-proxy/70521/3
Versions
Latest HEAD of development-v6 branch, c835795a7bfdadee37a431d5e78337197b36383b
Platform
OS:
Platform:
Compiler
CMake:
Expected behavior
Successful build.
Actual behavior / bug
Build failure:
Steps to reproduce
Steps to reproduce the behavior:
Must have GCC 14 to reproduce:
Additional context
In GCC 14
-Wextra
now implies-Wcalloc-transposed-args
This warning is...
However, IMO there is nothing wrong with your usage of
calloc()
so I choose to suppress this warning by passing-Wno-calloc-transposed-args
when GCC 14 is detected.