Re: [PATCH xserver 5/8] dmx: Silence a string truncation warning.

2018-04-06 Thread Emil Velikov
On 5 April 2018 at 18:13, Adam Jackson  wrote:
> ../hw/dmx/config/dmxparse.c: In function ‘dmxConfigCreateOption’:
> ../hw/dmx/config/dmxparse.c:385:13: warning: ‘strncpy’ output truncated 
> before terminating nul copying as many bytes from a string as its length 
> [-Wstringop-truncation]
>  strncpy(option->string + offset, p->string, len);
>  ^~~~
> ../hw/dmx/config/dmxparse.c:383:23: note: length computed here
>  int len = strlen(p->string);
>^
>
> The thing it's warning about is intentional, the surrounding code does
> its own nul-termination. Make that obvious by using memcpy instead.
>
> Signed-off-by: Adam Jackson 
> ---
>  hw/dmx/config/dmxparse.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/dmx/config/dmxparse.c b/hw/dmx/config/dmxparse.c
> index cf510844d6..f66143a6a5 100644
> --- a/hw/dmx/config/dmxparse.c
> +++ b/hw/dmx/config/dmxparse.c
> @@ -382,7 +382,7 @@ dmxConfigCreateOption(DMXConfigTokenPtr pStart,
>  if (p->string) {
>  int len = strlen(p->string);
>
> -strncpy(option->string + offset, p->string, len);
> +memcpy(option->string + offset, p->string, len);
Speaking of surrounding code - worth using option->string[offset] like
the rest of the function?

-Emil
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver 5/8] dmx: Silence a string truncation warning.

2018-04-05 Thread Adam Jackson
../hw/dmx/config/dmxparse.c: In function ‘dmxConfigCreateOption’:
../hw/dmx/config/dmxparse.c:385:13: warning: ‘strncpy’ output truncated before 
terminating nul copying as many bytes from a string as its length 
[-Wstringop-truncation]
 strncpy(option->string + offset, p->string, len);
 ^~~~
../hw/dmx/config/dmxparse.c:383:23: note: length computed here
 int len = strlen(p->string);
   ^

The thing it's warning about is intentional, the surrounding code does
its own nul-termination. Make that obvious by using memcpy instead.

Signed-off-by: Adam Jackson 
---
 hw/dmx/config/dmxparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/dmx/config/dmxparse.c b/hw/dmx/config/dmxparse.c
index cf510844d6..f66143a6a5 100644
--- a/hw/dmx/config/dmxparse.c
+++ b/hw/dmx/config/dmxparse.c
@@ -382,7 +382,7 @@ dmxConfigCreateOption(DMXConfigTokenPtr pStart,
 if (p->string) {
 int len = strlen(p->string);
 
-strncpy(option->string + offset, p->string, len);
+memcpy(option->string + offset, p->string, len);
 offset += len;
 if (p->next)
 option->string[offset++] = ' ';
-- 
2.16.2

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel