[PATCH stalld 46/52] stalld: fix type mismatches in detect_task_format

Wander Lairson Costa <[email protected]> Mon, 8 Jun 2026 15:31:56 -0300
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
detect_task_format() uses int for variables that hold byte counts and
read() return values. bufincrement and size should be size_t since they
accumulate memory sizes derived from page_size, and status should be
ssize_t to match the return type of read(). The die() call for
allocation failure uses %d with no matching argument, causing undefined
behavior on the error path.

Switch the variables to their correct types, replace malloc() with
calloc() for overflow-safe multiplication, and supply the missing
format argument with the proper %zu specifier.

Signed-off-by: Wander Lairson Costa <[email protected]>
---
 src/sched_debug.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/sched_debug.c b/src/sched_debug.c
index 25a11ce..5ddc331 100644
--- a/src/sched_debug.c
+++ b/src/sched_debug.c
@@ -193,22 +193,22 @@ static inline char *skip2word(char *ptr, int nwords)
  */
 static int detect_task_format(void)
 {
-	int bufincrement;
+	size_t bufincrement;
 	int retval = -1;
 	size_t bufsiz;
 	char *buffer;
-	int size = 0;
+	size_t size = 0;
 	char *ptr;
-	int status;
+	ssize_t status;
 	int fd;
 	int i, count=0;
 
 	bufsiz = bufincrement = BUFFER_PAGES * page_size;
 
-	buffer = malloc(bufsiz);
+	buffer = calloc(BUFFER_PAGES, page_size);
 
 	if (buffer == NULL)
-		die("unable to allocate %d bytes to read sched_debug");
+		die("unable to allocate %zu bytes to read sched_debug", bufsiz);
 
 	if ((fd = open(config_sched_debug_path, O_RDONLY)) < 0)
 		die("error opening sched_debug for reading: %s\n", strerror(errno));
-- 
2.54.0