diff --git a/include/endian.h b/include/endian.h index 267fbf00d..1c4a21de5 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 */ - -#ifndef ENDIAN_H_ -#define ENDIAN_H_ +#ifdef SHIM_UNIT_TEST +#include_next +#endif +#ifndef SHIM_ENDIAN_H_ +#define SHIM_ENDIAN_H_ #include @@ -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 5d74bdc21..62cf983a0 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 37eabe8cc..d941cd566 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 87605b26f..70d1637c1 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 aa0da1fdf..dc71941f1 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, ...) {