Skip to contentSkip to conversation

edid: silence a stringop-overflow warning

PATCH In review Marc-André Lureau 3 participants 3 messages Nov 10, 2018 – Nov 12, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 edid: silence a stringop-overflow warning

Simplify the code that doesn't need strncpy() since length of string is already computed.

/home/elmarco/src/qemu/hw/display/edid-generate.c: In function 'edid_desc_text':
/home/elmarco/src/qemu/hw/display/edid-generate.c:168:5: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]

     strncpy((char *)(desc + 5), text, len);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/elmarco/src/qemu/hw/display/edid-generate.c:164:11: note: length computed here
     len = strlen(text);
           ^~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 hw/display/edid-generate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/edid-generate.c +1 -1
index bdf5e1d4d4..77d9127344 100644
@@ -165,7 +165,7 @@ static void edid_desc_text(uint8_t *desc, uint8_t type,
     if (len > 12) {
         len = 12;
     }
-    strncpy((char *)(desc + 5), text, len);
+    memcpy(desc + 5, text, len);
     desc[5 + len] = '\n';
 }
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Marc-André Lureau

Simplify the code that doesn't need strncpy() since length of string is already computed.

/home/elmarco/src/qemu/hw/display/edid-generate.c: In function 'edid_desc_text':
/home/elmarco/src/qemu/hw/display/edid-generate.c:168:5: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]

     strncpy((char *)(desc + 5), text, len);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/elmarco/src/qemu/hw/display/edid-generate.c:164:11: note: length computed here
     len = strlen(text);
           ^~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 hw/display/edid-generate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/edid-generate.c +0 -0
index bdf5e1d4d4..77d9127344 100644

hw/display/edid-generate.c static void edid_desc_text(uint8_t *desc, uint8_t type, · line 170

Quoted 7 lines
hw/display/edid-generate.c +1 -1
@@ -165,7 +165,7 @@ static void edid_desc_text(uint8_t *desc, uint8_t type,
     if (len > 12) {
         len = 12;
     }
-    strncpy((char *)(desc + 5), text, len);
+    memcpy(desc + 5, text, len);
     desc[5 + len] = '\n';
 }
#2 lore raw
In reply to Marc-André Lureau
Quoted 5 lines · Marc-André Lureau

Simplify the code that doesn't need strncpy() since length of string is already computed.

/home/elmarco/src/qemu/hw/display/edid-generate.c: In function 'edid_desc_text':
/home/elmarco/src/qemu/hw/display/edid-generate.c:168:5: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]

Quoted 8 lines
     strncpy((char *)(desc + 5), text, len);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/elmarco/src/qemu/hw/display/edid-generate.c:164:11: note: length computed here
     len = strlen(text);
           ^~~~~~~~~~~~

cc1: all warnings being treated as errors

queued for 3.1

thanks,
Gerd