Commit 35bed3fa authored by Thomas Zimmermann's avatar Thomas Zimmermann

drivers/video: Fix -Wstringop-truncation in hdmi.c

Trying to copy into the string fields with strncpy() gives a warning from
gcc. Both fields are part of a packed HDMI header and do not require a
terminating \0 character.

../drivers/video/hdmi.c: In function 'hdmi_spd_infoframe_init':
../drivers/video/hdmi.c:230:2: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
  230 |  strncpy(frame->vendor, vendor, sizeof(frame->vendor));
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/video/hdmi.c:231:2: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
  231 |  strncpy(frame->product, product, sizeof(frame->product));
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Just use memcpy() instead.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20201021121241.17623-1-tzimmermann@suse.de
parent 7d6763ab
...@@ -221,14 +221,18 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_pack); ...@@ -221,14 +221,18 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame, int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
const char *vendor, const char *product) const char *vendor, const char *product)
{ {
size_t len;
memset(frame, 0, sizeof(*frame)); memset(frame, 0, sizeof(*frame));
frame->type = HDMI_INFOFRAME_TYPE_SPD; frame->type = HDMI_INFOFRAME_TYPE_SPD;
frame->version = 1; frame->version = 1;
frame->length = HDMI_SPD_INFOFRAME_SIZE; frame->length = HDMI_SPD_INFOFRAME_SIZE;
strncpy(frame->vendor, vendor, sizeof(frame->vendor)); len = strlen(vendor);
strncpy(frame->product, product, sizeof(frame->product)); memcpy(frame->vendor, vendor, min(len, sizeof(frame->vendor)));
len = strlen(product);
memcpy(frame->product, product, min(len, sizeof(frame->product)));
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment