You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2020/02/07 07:30:54 UTC

[mynewt-core] 03/03: fs/fatfs: Silence gcc warning

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

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 5916d6af14613ec3b003dc681fb0e823e67ca018
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Feb 6 16:00:46 2020 +0100

    fs/fatfs: Silence gcc warning
    
    GCC 9 emitted following warning
    
    repos/apache-mynewt-core/fs/fatfs/src/mynewt_glue.c:201:20: error: '%d' directive writing between 1 and 10 bytes into a region of size 4 [-Werror=format-overflow=]
      201 |     sprintf(path, "%d:", disk_number);
          |                    ^~
    repos/apache-mynewt-core/fs/fatfs/src/mynewt_glue.c:201:19: note: directive argument in the range [0, 2147483647]
      201 |     sprintf(path, "%d:", disk_number);
          |                   ^~~~~
    repos/apache-mynewt-core/fs/fatfs/src/mynewt_glue.c:201:5: note: 'sprintf' output between 3 and 12 bytes into a destination of size 4
      201 |     sprintf(path, "%d:", disk_number);
    
    Fix reduces supported disks number to 255 in print which should not be a problem.
---
 fs/fatfs/src/mynewt_glue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index b0637b7..d9141a4 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -184,7 +184,7 @@ drivenumber_from_disk(char *disk_name)
     struct mounted_disk *new_disk;
     int disk_number;
     FATFS *fs;
-    char path[DRIVE_LEN];
+    char path[6];
 
     disk_number = 0;
     if (disk_name) {
@@ -198,7 +198,7 @@ drivenumber_from_disk(char *disk_name)
 
     /* XXX: check for errors? */
     fs = malloc(sizeof(FATFS));
-    sprintf(path, "%d:", disk_number);
+    sprintf(path, "%d:", (uint8_t)disk_number);
     f_mount(fs, path, 1);
 
     /* FIXME */