diff options
author | Adam Jackson <ajax@redhat.com> | 2017-08-30 15:11:45 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2017-09-25 15:52:25 -0400 |
commit | 0e79797e3cb3f8fafe271f4f233a8a8fd25f2001 (patch) | |
tree | 51c17fb47f4d66f131a53501fb367088a16a7246 | |
parent | 69ab094a08513849bb68cd2750840e88db6e5933 (diff) |
os: Fix warning in LockServer
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@redhat.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
(cherry picked from commit aabf65d2a0206bd1a9c6e9a9f3153ded873dfd43)
-rw-r--r-- | os/utils.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/os/utils.c b/os/utils.c index 7379121b5..6dcf3285e 100644 --- a/os/utils.c +++ b/os/utils.c @@ -318,7 +318,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); |