From 2385718f1c89286336a98ae46207b407c07623d8 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 6 Mar 2022 19:56:27 +0800 Subject: [PATCH] graphics/nxwidgets: Fix the compiler warning src/cprogressbar.cxx: In member function 'virtual void NXWidgets::CProgressBar::drawContents(NXWidgets::CGraphicsPort*)': Error: src/cprogressbar.cxx:185:22: error: '%d' directive writing between 1 and 8 bytes into a region of size 6 [-Werror=format-overflow=] 185 | sprintf(text, "%d%%", (100 * m_value) / (m_maximumValue - m_minimumValue)); | ^~ src/cprogressbar.cxx:185:21: note: directive argument in the range [-3276800, 3276800] 185 | sprintf(text, "%d%%", (100 * m_value) / (m_maximumValue - m_minimumValue)); | ^~~~~~ src/cprogressbar.cxx:185:14: note: 'sprintf' output between 3 and 10 bytes into a destination of size 6 185 | sprintf(text, "%d%%", (100 * m_value) / (m_maximumValue - m_minimumValue)); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Xiang Xiao --- graphics/nxwidgets/src/cprogressbar.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/graphics/nxwidgets/src/cprogressbar.cxx b/graphics/nxwidgets/src/cprogressbar.cxx index 8c868805c..475b76dba 100644 --- a/graphics/nxwidgets/src/cprogressbar.cxx +++ b/graphics/nxwidgets/src/cprogressbar.cxx @@ -181,8 +181,9 @@ void CProgressBar::drawContents(CGraphicsPort *port) if (m_showPercentageText) { - char text[6]; - sprintf(text, "%d%%", (100 * m_value) / (m_maximumValue - m_minimumValue)); + char text[12]; + snprintf(text, sizeof(text), "%d%%", + (100 * m_value) / (m_maximumValue - m_minimumValue)); struct nxgl_point_s pos; pos.x = rect.getX() +