Skip to contentSkip to conversation

perf util: Fix compression checks returning -1 as bool

PATCH Applied Yunseong Kim 3 participants 3 messages Aug 22, 2025 – Sep 12, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf util: Fix compression checks returning -1 as bool

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 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
Fixes 88c74dc76a30 ("perf tools: Add gzip_is_compressed function")
---
 tools/perf/util/lzma.c | 2 +-
 tools/perf/util/zlib.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/lzma.c +1 -1
index bbcd2ffcf4bd..c355757ed391 100644
@@ -120,7 +120,7 @@ bool lzma_is_compressed(const char *input)
 	ssize_t rc;
 
 	if (fd < 0)
-		return -1;
+		return false;
 
 	rc = read(fd, buf, sizeof(buf));
 	close(fd);
tools/perf/util/zlib.c +1 -1
index 78d2297c1b67..1f7c06523059 100644
@@ -88,7 +88,7 @@ bool gzip_is_compressed(const char *input)
 	ssize_t rc;
 
 	if (fd < 0)
-		return -1;
+		return false;
 
 	rc = read(fd, buf, sizeof(buf));
 	close(fd);
Signature · 1 line
2.50.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Yunseong Kim

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.

Quoted 7 lines

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 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
Fixes 88c74dc76a30 ("perf tools: Add gzip_is_compressed function")

Thanks,
Ian

Quoted 34 lines
---
 tools/perf/util/lzma.c | 2 +-
 tools/perf/util/zlib.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/lzma.c +1 -1
index bbcd2ffcf4bd..c355757ed391 100644
@@ -120,7 +120,7 @@ bool lzma_is_compressed(const char *input)
        ssize_t rc;
 
        if (fd < 0)
-               return -1;
+               return false;
 
        rc = read(fd, buf, sizeof(buf));
        close(fd);
tools/perf/util/zlib.c +1 -2
index 78d2297c1b67..1f7c06523059 100644
@@ -88,7 +88,7 @@ bool gzip_is_compressed(const char *input)
        ssize_t rc;
 
        if (fd < 0)
-               return -1;
+               return false;
 
        rc = read(fd, buf, sizeof(buf));
        close(fd);
--

2.50.0

maintainer Applied
#2 lore raw
Quoted 14 lines · Ian Rogers
Quoted 13 lines · Yunseong Kim

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.

Quoted 5 lines
Quoted 3 lines
Fixes 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
Fixes 88c74dc76a30 ("perf tools: Add gzip_is_compressed function")

Thanks, applied to perf-tools-next,

- Arnaldo