summaryrefslogtreecommitdiffstats
path: root/firmware/font.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-02-15 01:15:59 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2023-02-15 01:15:59 -0500
commit91c8633e8ca7757731d6f5a10ff7c85738333cba (patch)
tree4ab687311a1c8d749f0ad1eaf7405d6b05fcf1a1 /firmware/font.c
parent3bb75e00399a063ed7a7c618bfce8c136d797839 (diff)
downloadrockbox-91c8633e8c.tar.gz
rockbox-91c8633e8c.zip
[BugFix] font.c filename was movable
stupid bug on my part font_filename was pointing to a movable alloc therefore that data could be moved out from under the returned pointer instead pin the internal calls to core_get_data and remove font_filename in favor of a function that checks if a filename matches the loaded font as this was all it was used for anyway Change-Id: Iebb47ffe3f81aa9d5e3968975f26d64283633ffc
Diffstat (limited to 'firmware/font.c')
-rw-r--r--firmware/font.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/firmware/font.c b/firmware/font.c
index 69c4fd40f8..8c268bea5f 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -152,13 +152,6 @@ void font_lock(int font_id, bool lock)
static struct buflib_callbacks buflibops = {buflibmove_callback, NULL, NULL };
-static inline struct font *pf_from_handle(int handle)
-{
- struct buflib_alloc_data *alloc = core_get_data(handle);
- struct font *pf = &alloc->font;
- return pf;
-}
-
static inline unsigned char *buffer_from_handle(int handle)
{
struct buflib_alloc_data *alloc = core_get_data(handle);
@@ -358,7 +351,7 @@ static int find_font_index(const char* path)
return FONT_SYSFIXED;
}
-const char* font_filename(int font_id)
+bool font_filename_matches_loaded_id(int font_id, char *filename)
{
if ( font_id < 0 || font_id >= MAXFONTS )
return NULL;
@@ -367,10 +360,10 @@ const char* font_filename(int font_id)
{
struct buflib_alloc_data *data = core_get_data(handle);
logf("%s id: [%d], %s", __func__, font_id, data->path);
- return data->path;
+ return strcmp(data->path, filename) == 0;
}
- return NULL;
+ return false;
}
static size_t font_glyphs_to_bufsize(struct font *pf, int glyphs)
@@ -688,15 +681,15 @@ static void font_enable(int font_id)
int handle = buflib_allocations[font_id];
if ( handle < 0 )
return;
- struct buflib_alloc_data *pdata = core_get_data(handle);
+ struct buflib_alloc_data *pdata = core_get_data_pinned(handle);
struct font *pf = &pdata->font;
if (pf->disabled && pf->fd < 0)
{
- const char *filename = font_filename(font_id);
- pf->fd = open(filename, O_RDONLY);
+ pf->fd = open(pdata->path, O_RDONLY);
pf->disabled = false;
}
+ core_put_data_pinned(pdata);
}
void font_enable_all(void)
@@ -932,25 +925,28 @@ static void glyph_cache_save(int font_id)
if ( handle < 0 )
return;
- struct font *pf = pf_from_handle(handle);
+ struct buflib_alloc_data *pdata = core_get_data_pinned(handle);
+ struct font *pf = &pdata->font;
+
if(pf && pf->fd >= 0)
{
char filename[MAX_PATH];
- font_path_to_glyph_path(font_filename(font_id), filename);
+ font_path_to_glyph_path(pdata->path, filename);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
- if (fd < 0)
- return;
-
- cache_pf = pf;
- cache_fd = fd;
- lru_traverse(&cache_pf->cache._lru, glyph_file_write);
- glyph_file_write(NULL);
- if (cache_fd >= 0)
+ if (fd >= 0)
{
- close(cache_fd);
- cache_fd = -1;
+ cache_pf = pf;
+ cache_fd = fd;
+ lru_traverse(&cache_pf->cache._lru, glyph_file_write);
+ glyph_file_write(NULL);
+ if (cache_fd >= 0)
+ {
+ close(cache_fd);
+ cache_fd = -1;
+ }
}
}
+ core_put_data_pinned(pdata);
return;
}