Skip to contentSkip to conversation

trace-cmd: Fix sizeof print warnings

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 1 message Nov 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Fix sizeof print warnings

The return type of sizeof() operator and strlen() function is size_t, which is machine specific. When printing these values with printf, a dedicated 'z' specifier should be used, to avoid compile warnings.

---
 tracecmd/trace-dump.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tracecmd/trace-dump.c +4 -4
index b19ce89a..2408a4ab 100644
@@ -152,13 +152,13 @@ static void dump_initial_format(int fd)
 
 	/* check initial bytes */
 	if (read_file_bytes(fd, buf, sizeof(magic)))
-		die("cannot read %ld bytes magic", sizeof(magic));
+		die("cannot read %zu bytes magic", sizeof(magic));
 	if (memcmp(buf, magic, sizeof(magic)) != 0)
 		die("wrong file magic");
 
 	/* check initial tracing string */
 	if (read_file_bytes(fd, buf, strlen(TRACING_STR)))
-		die("cannot read %ld bytes tracing string", strlen(TRACING_STR));
+		die("cannot read %zu bytes tracing string", strlen(TRACING_STR));
 	buf[strlen(TRACING_STR)] = 0;
 	if (strncmp(buf, TRACING_STR, strlen(TRACING_STR)) != 0)
 		die("wrong tracing string: %s", buf);
@@ -201,7 +201,7 @@ static void dump_header_page(int fd)
 
 	/* check header string */
 	if (read_file_bytes(fd, buf, strlen(HEAD_PAGE_STR) + 1))
-		die("cannot read %ld bytes header string", strlen(HEAD_PAGE_STR));
+		die("cannot read %zu bytes header string", strlen(HEAD_PAGE_STR));
 	if (strncmp(buf, HEAD_PAGE_STR, strlen(HEAD_PAGE_STR)) != 0)
 		die("wrong header string: %s", buf);
 
@@ -222,7 +222,7 @@ static void dump_header_event(int fd)
 
 	/* check header string */
 	if (read_file_bytes(fd, buf, strlen(HEAD_PAGE_EVENT) + 1))
-		die("cannot read %ld bytes header string", strlen(HEAD_PAGE_EVENT));
+		die("cannot read %zu bytes header string", strlen(HEAD_PAGE_EVENT));
 	if (strncmp(buf, HEAD_PAGE_EVENT, strlen(HEAD_PAGE_EVENT)) != 0)
 		die("wrong header string: %s", buf);
 
Signature · 1 line
2.33.1