[PATCH v1 05/48] tools lib: Silence -Wshorten-64-to-32 warnings

Ian Rogers
2025-04-01T18:24:47Z

tools/lib/api/fs/fs.c | 4 ++--
tools/lib/bitmap.c | 2 +-
tools/lib/string.c | 6 +++---
tools/lib/vsprintf.c | 6 +++---
4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index edec23406dbc..2c4677901de9 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -349,7 +349,7 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
{
struct io io;
char bf[128];
- int err;
+ ssize_t err;

io.fd = open(filename, O_RDONLY);
if (io.fd < 0)
@@ -363,7 +363,7 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
} else
err = 0;
close(io.fd);
- return err;
+ return (int)err;
}

int filename__write_int(const char *filename, int value)
diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
index 2178862bb114..87bd15e3968e 100644
--- a/tools/lib/bitmap.c
+++ b/tools/lib/bitmap.c
@@ -32,7 +32,7 @@ size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits,
char *buf, size_t size)
{
/* current bit is 'cur', most recently seen range is [rbot, rtop] */
- unsigned int cur, rbot, rtop;
+ size_t cur, rbot, rtop;
bool first = true;
size_t ret = 0;

diff --git a/tools/lib/string.c b/tools/lib/string.c
index 3126d2cff716..638e75b63538 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -182,7 +182,7 @@ char *strreplace(char *s, char old, char new)
return s;
}

-static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
+static void *check_bytes8(const u8 *start, u8 value, size_t bytes)
{
while (bytes) {
if (*start != value)
@@ -206,7 +206,7 @@ void *memchr_inv(const void *start, int c, size_t bytes)
{
u8 value = c;
u64 value64;
- unsigned int words, prefix;
+ size_t words, prefix;

if (bytes <= 16)
return check_bytes8(start, value, bytes);
@@ -216,7 +216,7 @@ void *memchr_inv(const void *start, int c, size_t bytes)
value64 |= value64 << 16;
value64 |= value64 << 32;

- prefix = (unsigned long)start % 8;
+ prefix = (size_t)start % 8;
if (prefix) {
u8 *r;

diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
index 8780b4cdab21..62028a5eea7e 100644
--- a/tools/lib/vsprintf.c
+++ b/tools/lib/vsprintf.c
@@ -8,7 +8,7 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
int i = vsnprintf(buf, size, fmt, args);
ssize_t ssize = size;

- return (i >= ssize) ? (ssize - 1) : i;
+ return (i >= ssize) ? (int)(ssize - 1) : i;
}

int scnprintf(char * buf, size_t size, const char * fmt, ...)
@@ -21,7 +21,7 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
i = vsnprintf(buf, size, fmt, args);
va_end(args);

- return (i >= ssize) ? (ssize - 1) : i;
+ return (i >= ssize) ? (int)(ssize - 1) : i;
}

int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
@@ -40,5 +40,5 @@ int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
buf[i] = 0x0;
}

- return (i >= ssize) ? (ssize - 1) : i;
+ return (i >= ssize) ? (int)(ssize - 1) : i;
}
--
2.49.0.504.g3bcea36a83-goog