comparison nuklear_ui/font_android.c @ 2684:c649bcc18487

Fix crash bug in Android fallback font loading path
author Michael Pavone <pavone@retrodev.com>
date Sat, 29 Mar 2025 23:54:45 -0700
parents 78abbabfd58d
children
comparison
equal deleted inserted replaced
2683:596786e43c24 2684:c649bcc18487
153 153
154 static uint8_t *try_load_font(char *path, uint32_t *size_out) 154 static uint8_t *try_load_font(char *path, uint32_t *size_out)
155 { 155 {
156 debug_message("Trying to load font %s\n", path); 156 debug_message("Trying to load font %s\n", path);
157 FILE *f = fopen(path, "rb"); 157 FILE *f = fopen(path, "rb");
158 free(path);
159 if (!f) { 158 if (!f) {
160 return NULL; 159 return NULL;
161 } 160 }
162 long size = file_size(f); 161 long size = file_size(f);
163 uint8_t *buffer = malloc(size); 162 uint8_t *buffer = malloc(size);
164 if (size != fread(buffer, 1, size, f)) { 163 if (size != fread(buffer, 1, size, f)) {
165 fclose(f); 164 fclose(f);
165 free(buffer);
166 return NULL; 166 return NULL;
167 } 167 }
168 fclose(f); 168 fclose(f);
169 sfnt_container *sfnt = load_sfnt(buffer, size); 169 sfnt_container *sfnt = load_sfnt(buffer, size);
170 if (!sfnt) { 170 if (!sfnt) {
179 char *path = default_font_path(); 179 char *path = default_font_path();
180 if (!path) { 180 if (!path) {
181 goto error; 181 goto error;
182 } 182 }
183 uint8_t *ret = try_load_font(path, size_out); 183 uint8_t *ret = try_load_font(path, size_out);
184 free(path);
184 if (ret) { 185 if (ret) {
185 return ret; 186 return ret;
186 } 187 }
187 error: 188 error:
188 //try some likely suspects if we failed to parse fonts.xml or failed to find the indicated font 189 //try some likely suspects if we failed to parse fonts.xml or failed to find the indicated font