Explorar o código

Add NULL-checks to path

Daniele Bartolini %!s(int64=10) %!d(string=hai) anos
pai
achega
44edd34281
Modificáronse 2 ficheiros con 14 adicións e 9 borrados
  1. 12 7
      src/core/filesystem/path.cpp
  2. 2 2
      src/core/filesystem/path.h

+ 12 - 7
src/core/filesystem/path.cpp

@@ -14,7 +14,7 @@ namespace path
 {
 	bool is_absolute(const char* path)
 	{
-		CE_ASSERT(path != NULL, "Path must be != NULL");
+		CE_ASSERT_NOT_NULL(path);
 #if CROWN_PLATFORM_POSIX
 		return strlen32(path) > 0
 			&& path[0] == PATH_SEPARATOR
@@ -30,12 +30,13 @@ namespace path
 
 	bool is_relative(const char* path)
 	{
+		CE_ASSERT_NOT_NULL(path);
 		return !is_absolute(path);
 	}
 
 	bool is_root(const char* path)
 	{
-		CE_ASSERT(path != NULL, "Path must be != NULL");
+		CE_ASSERT_NOT_NULL(path);
 #if CROWN_PLATFORM_POSIX
 		return is_absolute(path) && strlen32(path) == 1;
 #elif CROWN_PLATFORM_WINDOWS
@@ -43,24 +44,28 @@ namespace path
 #endif
 	}
 
-	void join(const char* a, const char* b, DynamicString& path)
+	void join(const char* path_a, const char* path_b, DynamicString& path)
 	{
-		const u32 la = strlen32(a);
-		const u32 lb = strlen32(b);
+		CE_ASSERT_NOT_NULL(path_a);
+		CE_ASSERT_NOT_NULL(path_b);
+		const u32 la = strlen32(path_a);
+		const u32 lb = strlen32(path_b);
 		path.reserve(la + lb + 1);
-		path += a;
+		path += path_a;
 		path += PATH_SEPARATOR;
-		path += b;
+		path += path_b;
 	}
 
 	const char* basename(const char* path)
 	{
+		CE_ASSERT_NOT_NULL(path);
 		const char* ls = strrchr(path, '/');
 		return ls == NULL ? path : ls + 1;
 	}
 
 	const char* extension(const char* path)
 	{
+		CE_ASSERT_NOT_NULL(path);
 		const char* ld = strrchr(path, '.');
 		return ld == NULL ? NULL : ld + 1;
 	}

+ 2 - 2
src/core/filesystem/path.h

@@ -30,8 +30,8 @@ namespace path
 	/// Returns whether the @a path is the root path.
 	bool is_root(const char* path);
 
-	/// Appends path @a b to @a a and fills @a path with the result.
-	void join(const char* a, const char* b, DynamicString& path);
+	/// Appends @a path_b to @a path_a and fills @a path with the result.
+	void join(const char* path_a, const char* path_b, DynamicString& path);
 
 	/// Returns the basename of the @a path.
 	/// @note