Skip to content

Commit

Permalink
Make 'make test' work on gcc 4.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
vathpela committed Mar 22, 2021
1 parent d4494b5 commit 33db42d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
10 changes: 6 additions & 4 deletions include/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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
2 changes: 1 addition & 1 deletion include/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
21 changes: 21 additions & 0 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,40 @@

#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
#define strrchr shim_strrchr
#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

Expand Down
23 changes: 23 additions & 0 deletions test-str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
{
Expand Down

0 comments on commit 33db42d

Please sign in to comment.