From e191e6bc8fd3290f5256bc989ddb73c6c3a54e87 Mon Sep 17 00:00:00 2001 From: nhmall Date: Thu, 20 Aug 2020 11:18:32 -0400 Subject: [PATCH] build warning fix on g++ >= 9 and Qt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ../win/Qt/qt_menu.cpp: In member function ‘virtual void nethack_qt_::NetHackQtTextWindow::UseRIP(int, time_t)’: ../win/Qt/qt_menu.cpp:680:54: warning: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size 17 [-Wformat-truncation=] 680 | snprintf(rip_line[NAME_LINE], STONE_LINE_LEN+1, "%s", g.plname); | ^~ ~~~~~~~~ In file included from /usr/include/stdio.h:867, from ../include/global.h:9, from ../include/config.h:608, from ../include/hack.h:10, from ../win/Qt/qt_menu.cpp:8: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: ‘__builtin_snprintf’ output between 1 and 32 bytes into a destination of size 17 67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../win/Qt/qt_menu.cpp: In member function ‘virtual void nethack_qt_::NetHackQtTextWindow::UseRIP(int, time_t)’: ../win/Qt/qt_menu.cpp:680:54: warning: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size 17 [-Wformat-truncation=] 680 | snprintf(rip_line[NAME_LINE], STONE_LINE_LEN+1, "%s", g.plname); | ^~ ~~~~~~~~ In file included from /usr/include/stdio.h:867, from ../include/global.h:9, from ../include/config.h:608, from ../include/hack.h:10, from ../win/Qt/qt_menu.cpp:8: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: ‘__builtin_snprintf’ output between 1 and 32 bytes into a destination of size 17 67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- sys/unix/hints/linux.2020 | 7 +++++++ sys/unix/hints/macOS.2020 | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/sys/unix/hints/linux.2020 b/sys/unix/hints/linux.2020 index df2bfc671..3a785a530 100755 --- a/sys/unix/hints/linux.2020 +++ b/sys/unix/hints/linux.2020 @@ -127,6 +127,13 @@ ifdef WANT_WIN_QT # Qt5 requires C++11 LINK = $(CXX) QTCXXFLAGS += -Wno-deprecated-declarations +ifeq "$(CCISCLANG)" "" +# get the version of g++ +GPPGTEQ9 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 9) +ifeq "$(GPPGTEQ9)" "1" +QTCXXFLAGS+= -Wno-format-truncation +endif #g++ version greater than or equal to 9 +endif #not clang QTCXXFLAGS += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --cflags) QTCXXFLAGS += -fPIC WINLIB += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --libs) diff --git a/sys/unix/hints/macOS.2020 b/sys/unix/hints/macOS.2020 index 31b92dba2..1a81d97ad 100755 --- a/sys/unix/hints/macOS.2020 +++ b/sys/unix/hints/macOS.2020 @@ -132,6 +132,13 @@ ifdef WANT_WIN_QT # Qt5 requires C++11 LINK = $(CXX) QTCXXFLAGS += -Wno-deprecated-declarations +ifeq "$(CCISCLANG)" "" +# get the version of g++ +GPPGTEQ9 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 9) +ifeq "$(GPPGTEQ9)" "1" +QTCXXFLAGS+= -Wno-format-truncation +endif #g++ version greater than or equal to 9 +endif #not clang QTCXXFLAGS += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --cflags) WINLIB += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --libs) WINSRC += $(WINQTSRC)