From bda32438f6bcc7df700834d033e6d2dc39751913 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 25 Nov 2023 15:44:30 -0800 Subject: [PATCH] Fixed crash in hmap_* functions --- data/dynos_cmap.cpp | 8 ++++++++ src/pc/djui/djui_unicode.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/data/dynos_cmap.cpp b/data/dynos_cmap.cpp index 458f9f11..c158be20 100644 --- a/data/dynos_cmap.cpp +++ b/data/dynos_cmap.cpp @@ -16,6 +16,7 @@ void* hmap_create() { } void* hmap_get(void* map, int64_t k) { + if (!map) { return NULL; } Map* m = reinterpret_cast (map); Map::iterator pos = m->find(k); if (pos == m->end()) { @@ -26,6 +27,7 @@ void* hmap_get(void* map, int64_t k) { } void hmap_put(void* map, int64_t k, void* v) { + if (!map) { return; } Map* m = reinterpret_cast (map); if (m->count(k) > 0) { m->erase(k); @@ -34,21 +36,25 @@ void hmap_put(void* map, int64_t k, void* v) { } void hmap_del(void* map, int64_t k) { + if (!map) { return; } Map* m = reinterpret_cast (map); m->erase(k); } void hmap_clear(void* map) { + if (!map) { return; } Map* m = reinterpret_cast (map); m->clear(); } size_t hmap_len(void* map) { + if (!map) { return 0; } Map* m = reinterpret_cast (map); return m->size(); } void* hmap_iter(void* map) { + if (!map) { return nullptr; } auto iter = new MapIter(); Map* m = reinterpret_cast (map); iter->map = m; @@ -56,6 +62,7 @@ void* hmap_iter(void* map) { } void* hmap_begin(void* iter) { + if (!iter) { return nullptr; } MapIter* i = reinterpret_cast (iter); i->itr = i->map->begin(); if (i->itr == i->map->end()) { @@ -65,6 +72,7 @@ void* hmap_begin(void* iter) { } void* hmap_next(void* iter) { + if (!iter) { return nullptr; } MapIter* i = reinterpret_cast (iter); i->itr++; if (i->itr == i->map->end()) { diff --git a/src/pc/djui/djui_unicode.c b/src/pc/djui/djui_unicode.c index a1d061e1..fddfd320 100644 --- a/src/pc/djui/djui_unicode.c +++ b/src/pc/djui/djui_unicode.c @@ -286,6 +286,8 @@ u32 djui_unicode_get_sprite_index(char* text) { } f32 djui_unicode_get_sprite_width(char* text, const f32 font_widths[]) { + if (!text) { return 0; } + // check for ASCI if ((u8)*text < 128) { // make sure it's in the valid range