Fixed crash in hmap_* functions

This commit is contained in:
MysterD 2023-11-25 15:44:30 -08:00 committed by Agent X
parent 97ea7780c8
commit 6d89c6e173
2 changed files with 10 additions and 0 deletions

View File

@ -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);
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*> (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*> (map);
m->erase(k);
}
void hmap_clear(void* map) {
if (!map) { return; }
Map* m = reinterpret_cast<Map*> (map);
m->clear();
}
size_t hmap_len(void* map) {
if (!map) { return 0; }
Map* m = reinterpret_cast<Map*> (map);
return m->size();
}
void* hmap_iter(void* map) {
if (!map) { return nullptr; }
auto iter = new MapIter();
Map* m = reinterpret_cast<Map*> (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<MapIter*> (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<MapIter*> (iter);
i->itr++;
if (i->itr == i->map->end()) {

View File

@ -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