Skip to content

Commit

Permalink
kselftest/cgroup: fix variable dereferenced before check warning
Browse files Browse the repository at this point in the history
cg_name(const char *root, const char *name) is always called with
non-empty root and name arguments, so there is no sense in checking
it in the function body (after using in strlen()).

Signed-off-by: Roman Gushchin <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Shuah Khan (Samsung OSG) <[email protected]>
  • Loading branch information
rgushchin authored and Shuah Khan (Samsung OSG) committed May 30, 2018
1 parent 7b04d1e commit adb31be
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions tools/testing/selftests/cgroup/cgroup_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ char *cg_name(const char *root, const char *name)
size_t len = strlen(root) + strlen(name) + 2;
char *ret = malloc(len);

if (name)
snprintf(ret, len, "%s/%s", root, name);
snprintf(ret, len, "%s/%s", root, name);

return ret;
}
Expand All @@ -70,8 +69,7 @@ char *cg_name_indexed(const char *root, const char *name, int index)
size_t len = strlen(root) + strlen(name) + 10;
char *ret = malloc(len);

if (name)
snprintf(ret, len, "%s/%s_%d", root, name, index);
snprintf(ret, len, "%s/%s_%d", root, name, index);

return ret;
}
Expand Down

0 comments on commit adb31be

Please sign in to comment.