You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/03/06 16:59:10 UTC

[incubator-nuttx-apps] 03/04: graphics/nxwidgets: Fix the compiler warning

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 2385718f1c89286336a98ae46207b407c07623d8
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Mar 6 19:56:27 2022 +0800

    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 <xi...@xiaomi.com>
---
 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 8c86880..475b76d 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() +