selftests/nolibc: use correct return type for read() and write()
authorThomas Weißschuh <linux@weissschuh.net>
Thu, 3 Aug 2023 07:28:55 +0000 (09:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Aug 2023 03:17:07 +0000 (05:17 +0200)
Avoid truncating values before comparing them.

As printf in nolibc doesn't support ssize_t add casts to int for
printing.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
tools/testing/selftests/nolibc/nolibc-test.c

index c2646707ccc2ddaac53b066a4ec23c279ee204ab..23a5e4c5708330a9ba5b0eb989d9d7708a90b98e 100644 (file)
@@ -1019,7 +1019,8 @@ int run_stdlib(int min, int max)
 
 static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...)
 {
-       int ret, fd, w, r;
+       int ret, fd;
+       ssize_t w, r;
        char buf[100];
        FILE *memfile;
        va_list args;
@@ -1041,7 +1042,7 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
        va_end(args);
 
        if (w != c) {
-               llen += printf(" written(%d) != %d", w, c);
+               llen += printf(" written(%d) != %d", (int)w, c);
                result(llen, FAIL);
                return 1;
        }
@@ -1055,7 +1056,7 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
        fclose(memfile);
 
        if (r != w) {
-               llen += printf(" written(%d) != read(%d)", w, r);
+               llen += printf(" written(%d) != read(%d)", (int)w, (int)r);
                result(llen, FAIL);
                return 1;
        }