[Bf-blender-cvs] [c9144f0cbb3] blender-v3.3-release: Fix potential undefined behavior printing a NULL pointer string

Campbell Barton noreply at git.blender.org
Mon Aug 22 04:12:00 CEST 2022


Commit: c9144f0cbb38c83457d9c78953d10bad1db206ac
Author: Campbell Barton
Date:   Mon Aug 22 12:01:54 2022 +1000
Branches: blender-v3.3-release
https://developer.blender.org/rBc9144f0cbb38c83457d9c78953d10bad1db206ac

Fix potential undefined behavior printing a NULL pointer string

Improve messages when the font directory can't be detected or is missing.

===================================================================

M	source/blender/blenfont/intern/blf_font_default.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font_default.c b/source/blender/blenfont/intern/blf_font_default.c
index 1bde25b5776..33dcce1539a 100644
--- a/source/blender/blenfont/intern/blf_font_default.c
+++ b/source/blender/blenfont/intern/blf_font_default.c
@@ -53,8 +53,15 @@ void BLF_load_font_stack()
   BLF_load_default(false);
   BLF_load_mono_default(false);
 
-  const char *path = BKE_appdir_folder_id(BLENDER_DATAFILES, BLF_DATAFILES_FONTS_DIR SEP_STR);
-  if (path && BLI_exists(path)) {
+  const char *datafiles_fonts_dir = BLF_DATAFILES_FONTS_DIR SEP_STR;
+  const char *path = BKE_appdir_folder_id(BLENDER_DATAFILES, datafiles_fonts_dir);
+  if (UNLIKELY(!path)) {
+    fprintf(stderr, "Font data directory \"%s\" could not be detected!\n", datafiles_fonts_dir);
+  }
+  else if (UNLIKELY(!BLI_exists(path))) {
+    fprintf(stderr, "Font data directory \"%s\" does not exist!\n", path);
+  }
+  else {
     struct direntry *dir;
     uint num_files = BLI_filelist_dir_contents(path, &dir);
     for (int f = 0; f < num_files; f++) {
@@ -74,7 +81,4 @@ void BLF_load_font_stack()
     }
     BLI_filelist_free(dir, num_files);
   }
-  else {
-    fprintf(stderr, "Fonts not found at %s\n", path);
-  }
 }



More information about the Bf-blender-cvs mailing list