From 5fc7009037e392ccec021b1251ddfff9a8604368 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 1 Aug 2022 21:35:03 +0200 Subject: fix some sign comparision warnings --- src/user/app/init/driver/ansiterm.c | 8 ++++---- src/user/lib/file.c | 2 +- src/user/lib/fs/dir.c | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/user') diff --git a/src/user/app/init/driver/ansiterm.c b/src/user/app/init/driver/ansiterm.c index 7b16537..7d842a5 100644 --- a/src/user/app/init/driver/ansiterm.c +++ b/src/user/app/init/driver/ansiterm.c @@ -50,12 +50,12 @@ static void scroll(void) { cursor.y--; } -static void font_blit(int glyph, int x, int y) { - if (glyph < 0 || glyph >= font.glyph_amt) glyph = 0; +static void font_blit(size_t glyph, int x, int y) { + if (glyph >= font.glyph_amt) glyph = 0; char *bitmap = font_data + font.glyph_size * glyph; - for (int i = 0; i < font.w; i++) { - for (int j = 0; j < font.h; j++) { + for (size_t i = 0; i < font.w; i++) { + for (size_t j = 0; j < font.h; j++) { size_t idx = j * font.w + i; char byte = bitmap[idx / 8]; byte >>= (7-(idx&7)); diff --git a/src/user/lib/file.c b/src/user/lib/file.c index 05ae2e8..b55a19d 100644 --- a/src/user/lib/file.c +++ b/src/user/lib/file.c @@ -151,7 +151,7 @@ size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restri char *fgets(char *buf, int size, FILE *f) { char c = '\0'; - size_t pos = 0; + long pos = 0; while (pos < (size-1) && c != '\n' && fread(&c, 1, 1, f)) buf[pos++] = c; buf[pos++] = '\0'; diff --git a/src/user/lib/fs/dir.c b/src/user/lib/fs/dir.c index 0529bfe..35028bd 100644 --- a/src/user/lib/fs/dir.c +++ b/src/user/lib/fs/dir.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -20,10 +21,14 @@ bool dir_append(struct dirbuild *db, const char *name) { bool dir_appendl(struct dirbuild *db, const char *name, size_t len) { if (db->error) return true; + if (len > (size_t)LONG_MAX) { + db->error = -1; + return true; + } len++; // account for the null byte - if (db->offset < len) { + if (db->offset < (long)len) { name += db->offset; len -= db->offset; db->offset = 0; -- cgit v1.2.3