summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-03-21 15:57:03 -0400
committerPeter Jones <pjones@redhat.com>2021-03-22 16:43:44 -0400
commit33db42def2ce6fe040b5f77642347e8b3c6420e5 (patch)
tree1cb9857acb523d9d5e2be6222328a38a5d4b1e74
parentd4494b5cff75b64a70cb27b2d8544b4debb7fa6b (diff)
downloadefi-boot-shim-33db42def2ce6fe040b5f77642347e8b3c6420e5.tar.gz
efi-boot-shim-33db42def2ce6fe040b5f77642347e8b3c6420e5.zip
Make 'make test' work on gcc 4.8.5
-rw-r--r--include/endian.h10
-rw-r--r--include/test.mk2
-rw-r--r--lib/string.c21
-rw-r--r--test-str.c23
-rw-r--r--test.c3
5 files changed, 54 insertions, 5 deletions
diff --git a/include/endian.h b/include/endian.h
index 267fbf00..1c4a21de 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -3,9 +3,11 @@
* endian.h - bswap decls that can't go in compiler.h
* Copyright Peter Jones <pjones@redhat.com>
*/
-
-#ifndef ENDIAN_H_
-#define ENDIAN_H_
+#ifdef SHIM_UNIT_TEST
+#include_next <endian.h>
+#endif
+#ifndef SHIM_ENDIAN_H_
+#define SHIM_ENDIAN_H_
#include <stdint.h>
@@ -15,5 +17,5 @@ mkbi1_(uint32_t, bswap32, uint32_t, x)
mkbi1_(uint64_t, bswap64, uint64_t, x)
#include "system/builtins_end_.h"
-#endif /* !ENDIAN_H_ */
+#endif /* !SHIM_ENDIAN_H_ */
// vim:fenc=utf-8:tw=75:noet
diff --git a/include/test.mk b/include/test.mk
index 5d74bdc2..62cf983a 100644
--- a/include/test.mk
+++ b/include/test.mk
@@ -21,7 +21,7 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
-Wno-unused \
-Werror \
-Werror=nonnull \
- -Werror=nonnull-compare \
+ $(shell $(CC) -Werror=nonnull-compare -E -x c /dev/null >/dev/null 2>&1 && echo -Werror=nonnull-compare) \
$(ARCH_DEFINES) \
-DEFI_FUNCTION_WRAPPER \
-DGNU_EFI_USE_MS_ABI -DPAGE_SIZE=4096 \
diff --git a/lib/string.c b/lib/string.c
index 37eabe8c..d941cd56 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -7,7 +7,13 @@
#ifdef SHIM_UNIT_TEST
#define strlen shim_strlen
+#ifdef strcmp
+#undef strcmp
+#endif
#define strcmp shim_strcmp
+#ifdef strncmp
+#undef strncmp
+#endif
#define strncmp shim_strncmp
#define strncasecmp shim_strncasecmp
#define strcasecmp shim_strcasecmp
@@ -15,11 +21,26 @@
#define strlen shim_strlen
#define strnlen shim_strnlen
#define strcpy shim_strcpy
+#ifdef strncpy
+#undef strncpy
+#endif
#define strncpy shim_strncpy
+#ifdef strdup
+#undef strdup
+#endif
#define strdup shim_strdup
+#ifdef strndup
+#undef strndup
+#endif
#define strndup shim_strndup
+#ifdef stpcpy
+#undef stpcpy
+#endif
#define stpcpy shim_stpcpy
#define strchrnul shim_strchrnul
+#ifdef strchr
+#undef strchr
+#endif
#define strchr shim_strchr
#endif
diff --git a/test-str.c b/test-str.c
index 87605b26..70d1637c 100644
--- a/test-str.c
+++ b/test-str.c
@@ -6,6 +6,8 @@
#pragma GCC diagnostic error "-Wnonnull"
#pragma GCC diagnostic error "-Wunused-function"
+#pragma GCC diagnostic warning "-Wcpp"
+
#ifndef SHIM_UNIT_TEST
#define SHIM_UNIT_TEST
#endif
@@ -1046,8 +1048,29 @@ test_strcat(void)
memset(s1, 0, 4096);
assert_equal_return(strcat(s1, s0), s1, -1, "got %p expected %p\n");
+ /* For unknown reasons, gcc 4.8.5 gives us this here:
+ * | In file included from shim.h:64:0,
+ * | from test-str.c:14:
+ * | test-str.c: In function 'test_strcat':
+ * | include/test.h:85:10: warning: array subscript is below array bounds [-Warray-bounds]
+ * | printf("%s:%d:got %lld, expected zero " fmt, __func__, \
+ * | ^
+ * | include/test.h:112:10: warning: array subscript is below array bounds [-Warray-bounds]
+ * | printf("%s:%d:got %lld, expected < 0 " fmt, __func__, \
+ * | ^
+ *
+ * This clearly isn't a useful error message, as it doesn't tell us
+ * /anything about the problem/, but also it isn't reported on
+ * later compilers, and it isn't clear that there's any problem
+ * when examining these functions.
+ *
+ * I don't know.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic warning "-Warray-bounds"
assert_zero_return(strncmp(s1, s0, sizeof(s)-1), 0, -1, "\n");
assert_negative_return(memcmp(s1, s0, sizeof(s)), 0, -1, "\n");
+#pragma GCC diagnostic pop
memset(s1, 0, 4096);
assert_equal_return(strcat(s1, s0), s1, -1, "got %p expected %p\n");
diff --git a/test.c b/test.c
index aa0da1fd..dc71941f 100644
--- a/test.c
+++ b/test.c
@@ -12,6 +12,9 @@
UINT8 in_protocol = 0;
int debug = DEFAULT_DEBUG_PRINT_STATE;
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#pragma GCC diagnostic ignored "-Wunused-function"
+
EFI_STATUS EFIAPI
LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
{