From e67eb4175b68229ddcb7314b1464b1aa19cd55f6 Mon Sep 17 00:00:00 2001 From: Francesco Cozzuto Date: Sun, 17 Aug 2025 14:42:39 +0200 Subject: [PATCH] Fix warnings --- 3p/WL.c | 38 +++++++++++++++++++++++++++----------- src/main.c | 2 +- src/template.c | 11 ++++++++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/3p/WL.c b/3p/WL.c index c18c4ff..9e3db75 100644 --- a/3p/WL.c +++ b/3p/WL.c @@ -68,12 +68,14 @@ static bool is_hex_digit(char c) return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } +#if 0 static char to_lower(char c) { if (c >= 'A' && c <= 'Z') return c - 'A' + 'a'; return c; } +#endif static int hex_digit_to_int(char c) { @@ -96,6 +98,7 @@ static bool streq(String a, String b) return true; } +#if 0 static bool streqcase(String a, String b) { if (a.len != b.len) @@ -105,7 +108,7 @@ static bool streqcase(String a, String b) return false; return true; } - +#endif #define REPORT(err, fmt, ...) report((err), __FILE__, __LINE__, fmt, ## __VA_ARGS__) static void report(Error *err, char *file, int line, char *fmt, ...) @@ -158,6 +161,7 @@ static bool grow_alloc(WL_Arena *a, char *p, int new_len) return true; } +#if 0 static String copystr(String s, WL_Arena *a) { char *p = alloc(a, s.len, 1); @@ -166,6 +170,7 @@ static String copystr(String s, WL_Arena *a) memcpy(p, s.ptr, s.len); return (String) { p, s.len }; } +#endif ///////////////////////////////////////////////////////////////////////// // WRITER @@ -188,14 +193,14 @@ static void write_raw_mem(Writer *w, void *ptr, int len) } static void write_raw_u8 (Writer *w, uint8_t x) { write_raw_mem(w, &x, SIZEOF(x)); } -static void write_raw_u16(Writer *w, uint16_t x) { write_raw_mem(w, &x, SIZEOF(x)); } +//static void write_raw_u16(Writer *w, uint16_t x) { write_raw_mem(w, &x, SIZEOF(x)); } static void write_raw_u32(Writer *w, uint32_t x) { write_raw_mem(w, &x, SIZEOF(x)); } -static void write_raw_u64(Writer *w, uint64_t x) { write_raw_mem(w, &x, SIZEOF(x)); } -static void write_raw_s8 (Writer *w, int8_t x) { write_raw_mem(w, &x, SIZEOF(x)); } -static void write_raw_s16(Writer *w, int16_t x) { write_raw_mem(w, &x, SIZEOF(x)); } -static void write_raw_s32(Writer *w, int32_t x) { write_raw_mem(w, &x, SIZEOF(x)); } +//static void write_raw_u64(Writer *w, uint64_t x) { write_raw_mem(w, &x, SIZEOF(x)); } +//static void write_raw_s8 (Writer *w, int8_t x) { write_raw_mem(w, &x, SIZEOF(x)); } +//static void write_raw_s16(Writer *w, int16_t x) { write_raw_mem(w, &x, SIZEOF(x)); } +//static void write_raw_s32(Writer *w, int32_t x) { write_raw_mem(w, &x, SIZEOF(x)); } static void write_raw_s64(Writer *w, int64_t x) { write_raw_mem(w, &x, SIZEOF(x)); } -static void write_raw_f32(Writer *w, float x) { write_raw_mem(w, &x, SIZEOF(x)); } +//static void write_raw_f32(Writer *w, float x) { write_raw_mem(w, &x, SIZEOF(x)); } static void write_raw_f64(Writer *w, double x) { write_raw_mem(w, &x, SIZEOF(x)); } static void write_text(Writer *w, String str) @@ -410,6 +415,7 @@ static bool consume_str(Scanner *s, String x) return true; } +#if 0 static void write_token(Writer *w, Token token) { switch (token.type) { @@ -463,6 +469,7 @@ static void write_token(Writer *w, Token token) } } +#endif static void parser_report(Parser *p, char *fmt, ...) { @@ -1990,6 +1997,14 @@ static void write_node(Writer *w, Node *node) write_text(w, S(")")); break; + case NODE_OPER_SHOVEL: + write_text(w, S("(")); + write_node(w, node->left); + write_text(w, S("<<")); + write_node(w, node->right); + write_text(w, S(")")); + break; + case NODE_VALUE_INT: write_text_s64(w, node->ival); break; @@ -3440,7 +3455,7 @@ static int write_instr(Writer *w, char *src, int len, String data) static int write_program(WL_Program program, char *dst, int cap) { - if (program.len < 3 * sizeof(uint32_t)) + if ((uint32_t) program.len < 3 * sizeof(uint32_t)) return -1; uint32_t magic; @@ -3454,7 +3469,7 @@ static int write_program(WL_Program program, char *dst, int cap) if (magic != WL_MAGIC) return -1; - if (code_len + data_len + 3 * sizeof(uint32_t) != program.len) + if (code_len + data_len + 3 * sizeof(uint32_t) != (uint32_t) program.len) return -1; String code = { program.ptr + 3 * sizeof(uint32_t) , code_len }; @@ -4529,7 +4544,7 @@ struct WL_Runtime { WL_Runtime *wl_runtime_init(WL_Arena *arena, WL_Program program) { - if (program.len < 3 * sizeof(uint32_t)) + if ((uint32_t) program.len < 3 * sizeof(uint32_t)) return NULL; uint32_t magic; @@ -4631,7 +4646,7 @@ static String rt_read_str(WL_Runtime *rt) ASSERT(rt->state == RUNTIME_LOOP); uint32_t off = rt_read_u32(rt); uint32_t len = rt_read_u32(rt); - ASSERT(off + len <= rt->data.len); + ASSERT(off + len <= (uint32_t) rt->data.len); return (String) { rt->data.ptr + off, len }; } @@ -5142,6 +5157,7 @@ WL_EvalResult wl_runtime_eval(WL_Runtime *rt) switch (rt->state) { + case RUNTIME_BEGIN: case RUNTIME_LOOP: UNREACHABLE; diff --git a/src/main.c b/src/main.c index 2877195..0a85312 100644 --- a/src/main.c +++ b/src/main.c @@ -113,7 +113,7 @@ int user_exists(SQLiteCache *dbcache, HTTP_String name, HTTP_String pass) int rawhashlen = sqlite3_column_bytes(stmt, 1); PasswordHash hash; - if (rawhashlen >= sizeof(hash.data)) { + if (rawhashlen >= (int) sizeof(hash.data)) { sqlite3_reset(stmt); return -500; } diff --git a/src/template.c b/src/template.c index d3b6cce..4e1a687 100644 --- a/src/template.c +++ b/src/template.c @@ -81,7 +81,7 @@ struct LoadedFile { char data[]; }; -static LoadedFile *load_file(WL_String path, WL_Arena *arena) +static LoadedFile *load_file(WL_String path) { char buf[1<<10]; if (path.len >= (int) sizeof(buf)) @@ -153,7 +153,7 @@ static int compile(WL_String path, WL_Program *program, WL_Arena *arena) for (int i = 0;; i++) { - LoadedFile *loaded_file = load_file(path, arena); + LoadedFile *loaded_file = load_file(path); if (loaded_file == NULL) { TRACE("Couldn't load file '%.*s'", path.len, path.ptr); free_loaded_files(loaded_file_head); @@ -295,6 +295,8 @@ static int query_routine(WL_Runtime *rt, SQLiteCache *dbcache) static void push_sysvar(WL_Runtime *rt, WL_String name, SQLiteCache *dbcache, int user_id, int post_id) { + (void) dbcache; + if (wl_streq(name, "login_user_id", -1)) { if (user_id < 0) @@ -337,7 +339,7 @@ static int get_or_create_program(TemplateCache *cache, WL_String path, WL_Arena memcpy(p, program.ptr, program.len); program.ptr = p; - if (sizeof(cache->pool->path) <= path.len) + if ((int) sizeof(cache->pool->path) <= path.len) return -1; memcpy(cache->pool[i].path, path.ptr, path.len); cache->pool[i].path[path.len] = '\0'; @@ -402,6 +404,9 @@ void template_eval(HTTP_ResponseBuilder builder, int status, case WL_EVAL_OUTPUT: http_response_builder_body(builder, (HTTP_String) { result.str.ptr, result.str.len }); break; + + default: + break; } } }