summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2023-02-23 18:31:23 +0100
committerdzwdz2023-02-23 18:31:23 +0100
commit55224307bf9b3e4231daca9ad4c4e3b6d734869b (patch)
tree18e0e3cc897efe60c96d3ee2ed02cb60a4571611
parentc9daa8909313b020df57605d0bd50ac48b208d58 (diff)
fix: printf related warnings
-rw-r--r--src/shared/printf.c8
-rw-r--r--src/user/app/iochk/iochk.c8
-rw-r--r--src/user/app/iostress/iostress.c4
-rw-r--r--src/user/app/shell/builtins.c4
-rw-r--r--src/user/app/shell/shell.c2
-rw-r--r--src/user/app/tests/shared/printf.c2
-rw-r--r--src/user/app/tests/tests.c2
7 files changed, 20 insertions, 10 deletions
diff --git a/src/shared/printf.c b/src/shared/printf.c
index 5134048..514b73e 100644
--- a/src/shared/printf.c
+++ b/src/shared/printf.c
@@ -8,6 +8,7 @@ enum lenmod {
LM_int,
LM_long,
LM_longlong,
+ LM_size,
};
struct out_state {
@@ -165,6 +166,10 @@ int __printf_internal(const char *fmt, va_list argp,
c = *fmt++;
}
break;
+ case 'z':
+ lm = LM_size;
+ c = *fmt++;
+ break;
default:
lm = LM_int;
break;
@@ -198,6 +203,7 @@ int __printf_internal(const char *fmt, va_list argp,
if (lm == LM_int) n = va_arg(argp, unsigned int);
else if (lm == LM_long) n = va_arg(argp, unsigned long);
else if (lm == LM_longlong) n = va_arg(argp, unsigned long long);
+ else if (lm == LM_size) n = va_arg(argp, size_t);
output_uint16(&os, &m, n);
break;
@@ -205,6 +211,7 @@ int __printf_internal(const char *fmt, va_list argp,
if (lm == LM_int) n = va_arg(argp, unsigned int);
else if (lm == LM_long) n = va_arg(argp, unsigned long);
else if (lm == LM_longlong) n = va_arg(argp, unsigned long long);
+ else if (lm == LM_size) n = va_arg(argp, size_t);
output_uint(&os, &m, n, '\0');
break;
@@ -213,6 +220,7 @@ int __printf_internal(const char *fmt, va_list argp,
if (lm == LM_int) ns = va_arg(argp, int);
else if (lm == LM_long) ns = va_arg(argp, long);
else if (lm == LM_longlong) ns = va_arg(argp, long long);
+ else if (lm == LM_size) ns = va_arg(argp, size_t);
sign = '\0';
if (ns < 0) {
ns = -ns;
diff --git a/src/user/app/iochk/iochk.c b/src/user/app/iochk/iochk.c
index 9703919..0850821 100644
--- a/src/user/app/iochk/iochk.c
+++ b/src/user/app/iochk/iochk.c
@@ -30,7 +30,7 @@ void check(hid_t h) {
long offlast = 0;
long retlast = _sys_read(h, buflast, buflen, offlast);
if (retlast < 0) {
- eprintf("error %d when reading at offset %d", retlast, offlast);
+ eprintf("error %ld when reading at offset %ld", retlast, offlast);
goto end;
}
@@ -43,14 +43,14 @@ void check(hid_t h) {
long retcur = _sys_read(h, bufcur, buflen, offcur);
if (retcur < 0) {
- eprintf("error %d when reading at offset %d", retlast, offcur);
+ eprintf("error %ld when reading at offset %ld", retlast, offcur);
break;
}
if (retcur < retlast + offlast - offcur) {
- verbosef("warn: unexpected ret %d < %d + %d - %d\n", retcur, retlast, offlast, offcur);
+ verbosef("warn: unexpected ret %ld < %ld + %ld - %ld\n", retcur, retlast, offlast, offcur);
}
if (memcmp(buflast + diff, bufcur, retlast - diff)) {
- eprintf("unconsistent read from offsets %d and %d", offlast, offcur);
+ eprintf("inconsistent read from offsets %ld and %ld", offlast, offcur);
}
offlast = offcur;
diff --git a/src/user/app/iostress/iostress.c b/src/user/app/iostress/iostress.c
index 3a3a23c..ac555de 100644
--- a/src/user/app/iostress/iostress.c
+++ b/src/user/app/iostress/iostress.c
@@ -35,9 +35,9 @@ int main(int argc, char **argv) {
for (long i = 0; i < num_runs; i++) {
uint64_t scaled = results[i] / 3000;
total += scaled;
- fprintf(stderr, "run %u: %u\n", i, scaled);
+ fprintf(stderr, "run %ld: %lu\n", i, scaled);
}
- fprintf(stderr, "%u calls, %u bytes. avg %u\n", num_calls, num_bytes, total / num_runs);
+ fprintf(stderr, "%lu calls, %lu bytes. avg %lu\n", num_calls, num_bytes, total / num_runs);
return 0;
}
diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c
index e0f848e..734370b 100644
--- a/src/user/app/shell/builtins.c
+++ b/src/user/app/shell/builtins.c
@@ -125,7 +125,7 @@ void cmd_hexdump(int argc, char **argv) {
}
continue;
} else skipped = false;
- printf("%08x ", pos + i);
+ printf("%08zx ", pos + i);
for (size_t j = i; j < i + 8 && j < len; j++)
printf("%02x ", buf[j]);
@@ -148,7 +148,7 @@ void cmd_hexdump(int argc, char **argv) {
}
pos += len;
}
- printf("%08x\n", pos);
+ printf("%08zx\n", pos);
fclose(file);
}
}
diff --git a/src/user/app/shell/shell.c b/src/user/app/shell/shell.c
index 5808de1..d2d7e37 100644
--- a/src/user/app/shell/shell.c
+++ b/src/user/app/shell/shell.c
@@ -72,7 +72,7 @@ void run_args(int argc, char **argv, struct redir *redir) {
uint64_t div = 3000;
run_args(argc - 1, argv + 1, redir);
time = __rdtsc() - time;
- printf("%u ns (assuming 3GHz)\n", time / div);
+ printf("%lu ns (assuming 3GHz)\n", time / div);
return;
} else if (!strcmp(argv[0], "exit")) {
exit(0);
diff --git a/src/user/app/tests/shared/printf.c b/src/user/app/tests/shared/printf.c
index 71122f5..d8df48a 100644
--- a/src/user/app/tests/shared/printf.c
+++ b/src/user/app/tests/shared/printf.c
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <string.h>
+#pragma GCC diagnostic ignored "-Wformat-truncation"
+
static void test_printf(void) {
char buf[64];
memset(buf, '?', 64);
diff --git a/src/user/app/tests/tests.c b/src/user/app/tests/tests.c
index 7139fc7..2cb97cd 100644
--- a/src/user/app/tests/tests.c
+++ b/src/user/app/tests/tests.c
@@ -15,7 +15,7 @@ void run_test(void (*fn)()) {
} else {
/* successful tests must return 0 */
if (_sys_await() != 0) {
- test_failf("%p, base %p", (void*)fn - (void*)_image_base, _image_base);
+ test_failf("%p, base %p", (void*)((void*)fn - (void*)_image_base), _image_base);
}
}
}