[PATCH xserver] os: Fix warning in LockServer

Alan Coopersmith alan.coopersmith at oracle.com
Wed Aug 30 19:31:54 UTC 2017


On 08/30/17 12:11 PM, Adam Jackson wrote:
> The meson build gives me:
> 
> ../os/utils.c: In function ‘LockServer’:
> ../os/utils.c:310:40: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
>       snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
>                                          ^~~~~~~~~
> ../os/utils.c:310:5: note: ‘snprintf’ output between 12 and 13 bytes into a destination of size 12
>       snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
>       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Which seems to be due to the %d part meaning that a negative number's -
> sign would be one wider than we're expecting. Fine, just coerce it to
> unsigned.
> 
> Signed-off-by: Adam Jackson <ajax at redhat.com>
> ---
>   os/utils.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/os/utils.c b/os/utils.c
> index 1972aa120a..8a758f0b9a 100644
> --- a/os/utils.c
> +++ b/os/utils.c
> @@ -307,7 +307,7 @@ LockServer(void)
>       }
>       if (lfd < 0)
>           FatalError("Could not create lock file in %s\n", tmp);
> -    snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
> +    snprintf(pid_str, sizeof(pid_str), "%10lu\n", (unsigned long) getpid());
>       if (write(lfd, pid_str, 11) != 11)
>           FatalError("Could not write pid to lock file in %s\n", tmp);
>       (void) fchmod(lfd, 0444);
> 

Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

-- 
	-Alan Coopersmith-               alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - https://blogs.oracle.com/alanc


More information about the xorg-devel mailing list