Fix crash when there are 0 font families.

Running Tux Paint under macOS in Korean mode (and some other languages) causes
it to crash, unless "load system fonts" option is also enabled. Some
investigation showed the issue occurs when num_font_families is 0 in fonts.c.
This change removes the assumption from the code that assumes num_font_families
has at least one record.
This commit is contained in:
Mark K. Kim 2018-06-26 01:28:43 -04:00
parent 21813ad860
commit 93c1ad5dc3
2 changed files with 13 additions and 3 deletions

View file

@ -7,8 +7,8 @@ Starting with 0.9.23, however, Tux Paint for macOS is built as though it were a
Linux application.
REQUIREMENTS
------------
PREREQUISITES
-------------
Although Tux Paint is built without the XCode IDE, XCode itself is still required
to build Tux Paint. Download it from the App Store, and launch it once to
accept its license agreements. Also install XCode command line tools using the

View file

@ -900,7 +900,7 @@ static void groupfonts(void)
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontscore);
//printf("groupfonts() qsort(user_font_families 2...)\n");
//fflush(stdout);
if (user_font_families[0]->score < 0)
if (num_font_families > 0 && user_font_families[0]->score < 0)
printf("sorted the wrong way, or all fonts were unusable\n");
#if 0
// THREADED_FONTS
@ -1007,8 +1007,18 @@ static void loadfonts(SDL_Surface * screen, const char *const dir)
free(homedirdir);
#endif
#ifdef DEBUG
printf("Grouping fonts...\n");
fflush(stdout);
#endif
groupfonts();
#ifdef DEBUG
printf("Finished loading the fonts\n");
fflush(stdout);
#endif
font_thread_done = 1;
waiting_for_fonts = 0;
// FIXME: need a memory barrier here