|
Paolo Bonzini |
6ea72c |
From 3416fa678a9b634910faffbf9479a82f4969f7b1 Mon Sep 17 00:00:00 2001
|
|
Paolo Bonzini |
6ea72c |
From: Laszlo Ersek <lersek@redhat.com>
|
|
Paolo Bonzini |
6ea72c |
Date: Fri, 2 Mar 2018 19:09:22 +0100
|
|
Paolo Bonzini |
6ea72c |
Subject: [PATCH 1/3] BaseTools/header.makefile: add "-Wno-stringop-truncation"
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
gcc-8 (which is part of Fedora 28) enables the new warning
|
|
Paolo Bonzini |
6ea72c |
"-Wstringop-truncation" in "-Wall". This warning is documented in detail
|
|
Paolo Bonzini |
6ea72c |
at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the
|
|
Paolo Bonzini |
6ea72c |
introduction says
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
> Warn for calls to bounded string manipulation functions such as strncat,
|
|
Paolo Bonzini |
6ea72c |
> strncpy, and stpncpy that may either truncate the copied string or leave
|
|
Paolo Bonzini |
6ea72c |
> the destination unchanged.
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
It breaks the BaseTools build with:
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
> EfiUtilityMsgs.c: In function 'PrintMessage':
|
|
Paolo Bonzini |
6ea72c |
> EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying
|
|
Paolo Bonzini |
6ea72c |
> between 0 and 511 bytes from a string of length 511
|
|
Paolo Bonzini |
6ea72c |
> [-Werror=stringop-truncation]
|
|
Paolo Bonzini |
6ea72c |
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
|
|
Paolo Bonzini |
6ea72c |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Paolo Bonzini |
6ea72c |
> EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying
|
|
Paolo Bonzini |
6ea72c |
> between 0 and 511 bytes from a string of length 511
|
|
Paolo Bonzini |
6ea72c |
> [-Werror=stringop-truncation]
|
|
Paolo Bonzini |
6ea72c |
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
|
|
Paolo Bonzini |
6ea72c |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Paolo Bonzini |
6ea72c |
> EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying
|
|
Paolo Bonzini |
6ea72c |
> between 0 and 511 bytes from a string of length 511
|
|
Paolo Bonzini |
6ea72c |
> [-Werror=stringop-truncation]
|
|
Paolo Bonzini |
6ea72c |
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
|
|
Paolo Bonzini |
6ea72c |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
The right way to fix the warning would be to implement string concat with
|
|
Paolo Bonzini |
6ea72c |
snprintf(). However, Microsoft does not appear to support snprintf()
|
|
Paolo Bonzini |
6ea72c |
before VS2015
|
|
Paolo Bonzini |
6ea72c |
<https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010>,
|
|
Paolo Bonzini |
6ea72c |
so we just have to shut up the warning. The strncat() calls flagged above
|
|
Paolo Bonzini |
6ea72c |
are valid BTW.
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
|
|
Paolo Bonzini |
6ea72c |
Cc: Cole Robinson <crobinso@redhat.com>
|
|
Paolo Bonzini |
6ea72c |
Cc: Liming Gao <liming.gao@intel.com>
|
|
Paolo Bonzini |
6ea72c |
Cc: Paolo Bonzini <pbonzini@redhat.com>
|
|
Paolo Bonzini |
6ea72c |
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
|
|
Paolo Bonzini |
6ea72c |
Contributed-under: TianoCore Contribution Agreement 1.1
|
|
Paolo Bonzini |
6ea72c |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
Paolo Bonzini |
6ea72c |
Message-Id: <20180302180924.4312-2-lersek@redhat.com>
|
|
Paolo Bonzini |
6ea72c |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Paolo Bonzini |
6ea72c |
---
|
|
Paolo Bonzini |
6ea72c |
BaseTools/Source/C/Makefiles/header.makefile | 4 ++--
|
|
Paolo Bonzini |
6ea72c |
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
Paolo Bonzini |
6ea72c |
|
|
Paolo Bonzini |
6ea72c |
diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
|
|
Paolo Bonzini |
6ea72c |
index 063982b82f..6c3826aecb 100644
|
|
Paolo Bonzini |
6ea72c |
--- a/BaseTools/Source/C/Makefiles/header.makefile
|
|
Paolo Bonzini |
6ea72c |
+++ b/BaseTools/Source/C/Makefiles/header.makefile
|
|
Paolo Bonzini |
6ea72c |
@@ -47,9 +47,9 @@ INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKE
|
|
Paolo Bonzini |
6ea72c |
BUILD_CPPFLAGS = $(INCLUDE) -O2
|
|
Paolo Bonzini |
6ea72c |
ifeq ($(DARWIN),Darwin)
|
|
Paolo Bonzini |
6ea72c |
# assume clang or clang compatible flags on OS X
|
|
Paolo Bonzini |
6ea72c |
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g
|
|
Paolo Bonzini |
6ea72c |
+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
|
|
Paolo Bonzini |
6ea72c |
else
|
|
Paolo Bonzini |
6ea72c |
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-unused-result -nostdlib -c -g
|
|
Paolo Bonzini |
6ea72c |
+BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostdlib -c -g
|
|
Paolo Bonzini |
6ea72c |
endif
|
|
Paolo Bonzini |
6ea72c |
BUILD_LFLAGS =
|
|
Paolo Bonzini |
6ea72c |
BUILD_CXXFLAGS = -Wno-unused-result
|
|
Paolo Bonzini |
6ea72c |
--
|
|
Paolo Bonzini |
6ea72c |
2.14.3
|
|
Paolo Bonzini |
6ea72c |
|