[Bf-blender-cvs] [58945b07f11] master: Cleanup: remove paranoid NULL checks

Campbell Barton noreply at git.blender.org
Fri Sep 9 09:46:59 CEST 2022


Commit: 58945b07f1171d5f29018e3561870d99efc3597a
Author: Campbell Barton
Date:   Fri Sep 9 17:40:19 2022 +1000
Branches: master
https://developer.blender.org/rB58945b07f1171d5f29018e3561870d99efc3597a

Cleanup: remove paranoid NULL checks

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

M	source/blender/blenlib/BLI_path_util.h
M	source/blender/blenlib/intern/path_util.c

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

diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 06dd9ab0db9..a2caaa0851b 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -44,7 +44,8 @@ const char *BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
  * \param relabase: Optional prefix to substitute for "//" on front of `dir`.
  * \param string: Area to return result.
  */
-void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
+void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file)
+    ATTR_NONNULL(2, 3, 4);
 /**
  * Ensures that the parent directory of `name` exists.
  *
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 623dd572b11..73396fb34b1 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1206,19 +1206,8 @@ bool BLI_make_existing_file(const char *name)
 
 void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file)
 {
-  int sl;
-
-  if (string) {
-    /* ensure this is always set even if dir/file are NULL */
-    string[0] = '\0';
-
-    if (ELEM(NULL, dir, file)) {
-      return; /* We don't want any NULLs */
-    }
-  }
-  else {
-    return; /* string is NULL, probably shouldn't happen but return anyway */
-  }
+  /* Ensure this is always set & the following `strcat` works as expected. */
+  string[0] = '\0';
 
   /* Resolve relative references */
   if (relabase && dir[0] == '/' && dir[1] == '/') {
@@ -1266,7 +1255,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c
 
   /* Make sure string ends in one (and only one) slash */
   /* first trim all slashes from the end of the string */
-  sl = strlen(string);
+  int sl = strlen(string);
   while ((sl > 0) && ELEM(string[sl - 1], '/', '\\')) {
     string[sl - 1] = '\0';
     sl--;



More information about the Bf-blender-cvs mailing list