Skip to content

Commit 4be14da

Browse files
kzall0cgregkh
authored andcommitted
perf util: Fix compression checks returning -1 as bool
[ Upstream commit 43fa114 ] The lzma_is_compressed and gzip_is_compressed functions are declared to return a "bool" type, but in case of an error (e.g., file open failure), they incorrectly returned -1. A bool type is a boolean value that is either true or false. Returning -1 for a bool return type can lead to unexpected behavior and may violate strict type-checking in some compilers. Fix the return value to be false in error cases, ensuring the function adheres to its declared return type improves for preventing potential bugs related to type mismatch. Fixes: 4b57fd4 ("perf tools: Add lzma_is_compressed function") Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Yunseong Kim <ysk@kzalloc.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Link: https://lore.kernel.org/r/20250822162506.316844-3-ysk@kzalloc.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ca37036 commit 4be14da

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

tools/perf/util/lzma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool lzma_is_compressed(const char *input)
113113
ssize_t rc;
114114

115115
if (fd < 0)
116-
return -1;
116+
return false;
117117

118118
rc = read(fd, buf, sizeof(buf));
119119
close(fd);

tools/perf/util/zlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool gzip_is_compressed(const char *input)
8888
ssize_t rc;
8989

9090
if (fd < 0)
91-
return -1;
91+
return false;
9292

9393
rc = read(fd, buf, sizeof(buf));
9494
close(fd);

0 commit comments

Comments
 (0)