Skip to content

Commit 1d212a8

Browse files
author
Laszlo Ersek
committed
BaseTools/header.makefile: add "-Wno-stringop-truncation"
gcc-8 (which is part of Fedora 28) enables the new warning "-Wstringop-truncation" in "-Wall". This warning is documented in detail at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the introduction says > Warn for calls to bounded string manipulation functions such as strncat, > strncpy, and stpncpy that may either truncate the copied string or leave > the destination unchanged. It breaks the BaseTools build with: > EfiUtilityMsgs.c: In function 'PrintMessage': > EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=stringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=stringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=stringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The right way to fix the warning would be to implement string concat with snprintf(). However, Microsoft does not appear to support snprintf() before VS2015 <https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010>, so we just have to shut up the warning. The strncat() calls flagged above are valid BTW. Cc: Ard Biesheuvel <[email protected]> Cc: Cole Robinson <[email protected]> Cc: Liming Gao <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Yonghong Zhu <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <[email protected]> Reviewed-by: Liming Gao <[email protected]>
1 parent 20203d3 commit 1d212a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

BaseTools/Source/C/Makefiles/header.makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKE
7171
BUILD_CPPFLAGS = $(INCLUDE) -O2
7272
ifeq ($(DARWIN),Darwin)
7373
# assume clang or clang compatible flags on OS X
74-
BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g
74+
BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-self-assign -Wno-unused-result -nostdlib -c -g
7575
else
76-
BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-unused-result -nostdlib -c -g
76+
BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostdlib -c -g
7777
endif
7878
BUILD_LFLAGS =
7979
BUILD_CXXFLAGS = -Wno-unused-result

0 commit comments

Comments
 (0)