|
| 1 | +From 1d212a83df0eaf32a6f5d4159beb2d77832e0231 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Laszlo Ersek <lersek@redhat.com> |
| 3 | +Date: Fri, 2 Mar 2018 17:11:52 +0100 |
| 4 | +Subject: [PATCH 01/11] BaseTools/header.makefile: add |
| 5 | + "-Wno-stringop-truncation" |
| 6 | + |
| 7 | +gcc-8 (which is part of Fedora 28) enables the new warning |
| 8 | +"-Wstringop-truncation" in "-Wall". This warning is documented in detail |
| 9 | +at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the |
| 10 | +introduction says |
| 11 | + |
| 12 | +> Warn for calls to bounded string manipulation functions such as strncat, |
| 13 | +> strncpy, and stpncpy that may either truncate the copied string or leave |
| 14 | +> the destination unchanged. |
| 15 | + |
| 16 | +It breaks the BaseTools build with: |
| 17 | + |
| 18 | +> EfiUtilityMsgs.c: In function 'PrintMessage': |
| 19 | +> EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying |
| 20 | +> between 0 and 511 bytes from a string of length 511 |
| 21 | +> [-Werror=stringop-truncation] |
| 22 | +> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); |
| 23 | +> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | +> EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying |
| 25 | +> between 0 and 511 bytes from a string of length 511 |
| 26 | +> [-Werror=stringop-truncation] |
| 27 | +> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); |
| 28 | +> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 29 | +> EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying |
| 30 | +> between 0 and 511 bytes from a string of length 511 |
| 31 | +> [-Werror=stringop-truncation] |
| 32 | +> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); |
| 33 | +> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 34 | + |
| 35 | +The right way to fix the warning would be to implement string concat with |
| 36 | +snprintf(). However, Microsoft does not appear to support snprintf() |
| 37 | +before VS2015 |
| 38 | +<https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010>, |
| 39 | +so we just have to shut up the warning. The strncat() calls flagged above |
| 40 | +are valid BTW. |
| 41 | + |
| 42 | +Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> |
| 43 | +Cc: Cole Robinson <crobinso@redhat.com> |
| 44 | +Cc: Liming Gao <liming.gao@intel.com> |
| 45 | +Cc: Paolo Bonzini <pbonzini@redhat.com> |
| 46 | +Cc: Yonghong Zhu <yonghong.zhu@intel.com> |
| 47 | +Contributed-under: TianoCore Contribution Agreement 1.1 |
| 48 | +Signed-off-by: Laszlo Ersek <lersek@redhat.com> |
| 49 | +Reviewed-by: Liming Gao <liming.gao@intel.com> |
| 50 | +--- |
| 51 | + BaseTools/Source/C/Makefiles/header.makefile | 4 ++-- |
| 52 | + 1 file changed, 2 insertions(+), 2 deletions(-) |
| 53 | + |
| 54 | +diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile |
| 55 | +index 0976973bdd..550f8b35bc 100644 |
| 56 | +--- a/BaseTools/Source/C/Makefiles/header.makefile |
| 57 | ++++ b/BaseTools/Source/C/Makefiles/header.makefile |
| 58 | +@@ -71,9 +71,9 @@ INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKE |
| 59 | + BUILD_CPPFLAGS = $(INCLUDE) -O2 |
| 60 | + ifeq ($(DARWIN),Darwin) |
| 61 | + # assume clang or clang compatible flags on OS X |
| 62 | +-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g |
| 63 | ++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 |
| 64 | + else |
| 65 | +-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-unused-result -nostdlib -c -g |
| 66 | ++BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostdlib -c -g |
| 67 | + endif |
| 68 | + BUILD_LFLAGS = |
| 69 | + BUILD_CXXFLAGS = -Wno-unused-result |
| 70 | +-- |
| 71 | +2.25.1 |
| 72 | + |
0 commit comments