Skip to content

Commit 33db42d

Browse files
committed
Make 'make test' work on gcc 4.8.5
1 parent d4494b5 commit 33db42d

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

include/endian.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* endian.h - bswap decls that can't go in compiler.h
44
* Copyright Peter Jones <pjones@redhat.com>
55
*/
6-
7-
#ifndef ENDIAN_H_
8-
#define ENDIAN_H_
6+
#ifdef SHIM_UNIT_TEST
7+
#include_next <endian.h>
8+
#endif
9+
#ifndef SHIM_ENDIAN_H_
10+
#define SHIM_ENDIAN_H_
911

1012
#include <stdint.h>
1113

@@ -15,5 +17,5 @@ mkbi1_(uint32_t, bswap32, uint32_t, x)
1517
mkbi1_(uint64_t, bswap64, uint64_t, x)
1618
#include "system/builtins_end_.h"
1719

18-
#endif /* !ENDIAN_H_ */
20+
#endif /* !SHIM_ENDIAN_H_ */
1921
// vim:fenc=utf-8:tw=75:noet

include/test.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
2121
-Wno-unused \
2222
-Werror \
2323
-Werror=nonnull \
24-
-Werror=nonnull-compare \
24+
$(shell $(CC) -Werror=nonnull-compare -E -x c /dev/null >/dev/null 2>&1 && echo -Werror=nonnull-compare) \
2525
$(ARCH_DEFINES) \
2626
-DEFI_FUNCTION_WRAPPER \
2727
-DGNU_EFI_USE_MS_ABI -DPAGE_SIZE=4096 \

lib/string.c

+21
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,40 @@
77

88
#ifdef SHIM_UNIT_TEST
99
#define strlen shim_strlen
10+
#ifdef strcmp
11+
#undef strcmp
12+
#endif
1013
#define strcmp shim_strcmp
14+
#ifdef strncmp
15+
#undef strncmp
16+
#endif
1117
#define strncmp shim_strncmp
1218
#define strncasecmp shim_strncasecmp
1319
#define strcasecmp shim_strcasecmp
1420
#define strrchr shim_strrchr
1521
#define strlen shim_strlen
1622
#define strnlen shim_strnlen
1723
#define strcpy shim_strcpy
24+
#ifdef strncpy
25+
#undef strncpy
26+
#endif
1827
#define strncpy shim_strncpy
28+
#ifdef strdup
29+
#undef strdup
30+
#endif
1931
#define strdup shim_strdup
32+
#ifdef strndup
33+
#undef strndup
34+
#endif
2035
#define strndup shim_strndup
36+
#ifdef stpcpy
37+
#undef stpcpy
38+
#endif
2139
#define stpcpy shim_stpcpy
2240
#define strchrnul shim_strchrnul
41+
#ifdef strchr
42+
#undef strchr
43+
#endif
2344
#define strchr shim_strchr
2445
#endif
2546

test-str.c

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#pragma GCC diagnostic error "-Wnonnull"
77
#pragma GCC diagnostic error "-Wunused-function"
88

9+
#pragma GCC diagnostic warning "-Wcpp"
10+
911
#ifndef SHIM_UNIT_TEST
1012
#define SHIM_UNIT_TEST
1113
#endif
@@ -1046,8 +1048,29 @@ test_strcat(void)
10461048

10471049
memset(s1, 0, 4096);
10481050
assert_equal_return(strcat(s1, s0), s1, -1, "got %p expected %p\n");
1051+
/* For unknown reasons, gcc 4.8.5 gives us this here:
1052+
* | In file included from shim.h:64:0,
1053+
* | from test-str.c:14:
1054+
* | test-str.c: In function 'test_strcat':
1055+
* | include/test.h:85:10: warning: array subscript is below array bounds [-Warray-bounds]
1056+
* | printf("%s:%d:got %lld, expected zero " fmt, __func__, \
1057+
* | ^
1058+
* | include/test.h:112:10: warning: array subscript is below array bounds [-Warray-bounds]
1059+
* | printf("%s:%d:got %lld, expected < 0 " fmt, __func__, \
1060+
* | ^
1061+
*
1062+
* This clearly isn't a useful error message, as it doesn't tell us
1063+
* /anything about the problem/, but also it isn't reported on
1064+
* later compilers, and it isn't clear that there's any problem
1065+
* when examining these functions.
1066+
*
1067+
* I don't know.
1068+
*/
1069+
#pragma GCC diagnostic push
1070+
#pragma GCC diagnostic warning "-Warray-bounds"
10491071
assert_zero_return(strncmp(s1, s0, sizeof(s)-1), 0, -1, "\n");
10501072
assert_negative_return(memcmp(s1, s0, sizeof(s)), 0, -1, "\n");
1073+
#pragma GCC diagnostic pop
10511074

10521075
memset(s1, 0, 4096);
10531076
assert_equal_return(strcat(s1, s0), s1, -1, "got %p expected %p\n");

test.c

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
UINT8 in_protocol = 0;
1313
int debug = DEFAULT_DEBUG_PRINT_STATE;
1414

15+
#pragma GCC diagnostic ignored "-Wunused-parameter"
16+
#pragma GCC diagnostic ignored "-Wunused-function"
17+
1518
EFI_STATUS EFIAPI
1619
LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
1720
{

0 commit comments

Comments
 (0)