Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Avoid using buflib names for storing font paths

Naming your allocations is more of a debugging feature; it's a
bad idea to abuse this feature for storing some random string.
The font code does exactly that to remember the path used to
load a font, and it's the only code that uses buflib names in
this way.

Store the path inside the font allocation instead as a regular
char array. For simplicity it's MAX_PATH sized, so this'll use
a bit more memory than the buflib name method, maybe 1-2 KiB if
a few fonts are loaded.

Change-Id: Ie286a1a273d6477af9e5d3f76e0534b62f72e8f7

+22 -5
+22 -5
firmware/font.c
··· 90 90 91 91 struct buflib_alloc_data { 92 92 struct font font; /* must be the first member! */ 93 + char path[MAX_PATH]; /* font path and filename */ 93 94 int refcount; /* how many times has this font been loaded? */ 94 95 unsigned char buffer[]; 95 96 }; ··· 331 332 while (index < MAXFONTS) 332 333 { 333 334 handle = buflib_allocations[index]; 334 - if (handle > 0 && !strcmp(core_get_name(handle), path)) 335 - return index; 335 + if (handle > 0) 336 + { 337 + struct buflib_alloc_data *data = core_get_data(handle); 338 + if(!strcmp(data->path, path)) 339 + return index; 340 + } 341 + 336 342 index++; 337 343 } 338 344 return FONT_SYSFIXED; ··· 344 350 return NULL; 345 351 int handle = buflib_allocations[font_id]; 346 352 if (handle > 0) 347 - return core_get_name(handle); 353 + { 354 + struct buflib_alloc_data *data = core_get_data(handle); 355 + return data->path; 356 + } 357 + 348 358 return NULL; 349 359 } 350 360 ··· 402 412 /* load a font with room for glyphs, limited to bufsize if not zero */ 403 413 int font_load_ex( const char *path, size_t buf_size, int glyphs ) 404 414 { 415 + /* needed to handle the font properly after it's loaded */ 416 + size_t path_len = strlen(path); 417 + if ( path_len >= MAX_PATH ) 418 + return -1; 419 + 405 420 //printf("\nfont_load_ex(%s, %d, %d)\n", path, buf_size, glyphs); 406 421 int fd = open(path, O_RDONLY|O_BINARY); 407 422 if ( fd < 0 ) ··· 510 525 font_id = open_slot; 511 526 512 527 /* allocate mem */ 513 - int handle = core_alloc_ex( path, 528 + int handle = core_alloc_ex( NULL, 514 529 bufsize + sizeof( struct buflib_alloc_data ), 515 530 &buflibops ); 516 531 if ( handle <= 0 ) ··· 521 536 core_pin(handle); 522 537 pdata = core_get_data(handle); 523 538 pdata->refcount = 1; 539 + 540 + /* save load path so we can recognize this font later */ 541 + memcpy(pdata->path, path, path_len+1); 524 542 525 543 /* load and init */ 526 544 struct font *pf = &pdata->font; ··· 594 612 pdata->refcount--; 595 613 if (pdata->refcount < 1) 596 614 { 597 - //printf("freeing id: %d %s\n", font_id, core_get_name(*handle)); 598 615 if (pf && pf->fd >= 0) 599 616 { 600 617 glyph_cache_save(font_id);