libtracefs: Silence non-literal-null-conversion warning
PATCH 1/2 libtracefs: Silence non-literal-null-conversion warning
On clang the warning looks like:
src/tracefs-utils.c:473:15: error: expression which evaluates to zero treated as a null pointer constant of type 'char *' [-Werror,-Wnon-literal-null-conversion]
list[size] = '\0';
--- src/tracefs-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/tracefs-utils.c +1 -1
@@ -470,7 +470,7 @@ int tracefs_list_pop(char **list) size--; *list = (char *)size; list++; - list[size] ='\0' ; + list[size] =NULL ;return 0 ; }
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
PATCH 2/2 libtracefs: Silence sometimes-uninitialized warning
Warning generated by clang:
src/tracefs-events.c:1046:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (!systems)
^~~~~~~~
src/tracefs-events.c:1101:9: note: uninitialized use occurs here
return ret;
^~~
src/tracefs-events.c:1046:2: note: remove the 'if' if its condition is always false
if (!systems)
^~~~~~~~~~~~~
src/tracefs-events.c:1038:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0--- src/tracefs-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/tracefs-events.c +1 -1
@@ -1035,7 +1035,7 @@ static int event_enable_disable(struct tracefs_instance *instance,regex_t system_re, event_re;char **systems;char **events =NULL ; -int ret; +int ret =-1 ;int s, e;/* Handle all events first */
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
Re: [PATCH 2/2] libtracefs: Silence sometimes-uninitialized warning
Quoted 15 lines · On Tue, 3 Aug 2021 17:41:09 -0700 Ian Rogers <[email protected]> wrote:
Warning generated by clang:
src/tracefs-events.c:1046:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]if (!systems) ^~~~~~~~ src/tracefs-events.c:1101:9: note: uninitialized use occurs here return ret; ^~~ src/tracefs-events.c:1046:2: note: remove the 'if' if its condition is always false if (!systems) ^~~~~~~~~~~~~ src/tracefs-events.c:1038:9: note: initialize the variable 'ret' to silence this warning int ret; ^ = 0
That's a legitimate path to have ret returned without being initialized.
I'll add both patches to my next push.
Thanks!
-- Steve
Quoted 19 lines
Signed-off-by Ian Rogers <[email protected]>--- src/tracefs-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/tracefs-events.c +1
-1@@ -1035,7 +1035,7 @@ static int event_enable_disable(struct tracefs_instance *instance,regex_t system_re, event_re;char **systems;char **events =NULL ; -int ret; +int ret =-1 ;int s, e;/* Handle all events first */
src/tracefs-utils.c int tracefs_list_pop(char **list) · line 473
Quoted 10 lines · On Tue, 3 Aug 2021 17:41:08 -0700 Ian Rogers <[email protected]> wrote:
src/tracefs-utils.c +1
-1@@ -470,7 +470,7 @@ int tracefs_list_pop(char **list) size--; *list = (char *)size; list++; - list[size] ='\0' ; + list[size] =NULL ;
Regardless of a clang warning, that code was an oops.
Thanks for the fix.
-- Steve
Quoted 3 lines
src/tracefs-utils.c +0
-0return 0 ; }