lkml.org 
[lkml]   [2018]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] tools: Fix str_error_r() Werror=restrict build
Date
Commit c8b5f2c96d1bf6c ("tools: Introduce str_error_r()") added
an str_error_r() wrapper which makes gcc8 unhappy due to
restrict-qualified parameter aliasing violation:

../lib/str_error_r.c: In function ‘str_error_r’:
../lib/str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
^~~~~~~~
cc1: all warnings being treated as errors

Workaround that aliasing error by creating an additional stack
variable which holds the buf pointer value we passed to strerror_r().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
tools/lib/str_error_r.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
index d6d65537b0d9..11c3425f272b 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/str_error_r.c
@@ -21,7 +21,12 @@
char *str_error_r(int errnum, char *buf, size_t buflen)
{
int err = strerror_r(errnum, buf, buflen);
- if (err)
- snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
+ if (err) {
+ char *err_buf = buf;
+
+ snprintf(err_buf, buflen,
+ "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d",
+ errnum, buf, buflen, err);
+ }
return buf;
}
--
2.16.2
\
 
 \ /
  Last update: 2018-03-19 06:56    [W:0.080 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site