Browse Source

GetDirectoryPath: return NULL, don't crash when no slash

Noted in #634.
Ahmad Fatoum 7 years ago
parent
commit
85213795d1
1 changed files with 3 additions and 0 deletions
  1. 3 0
      src/core.c

+ 3 - 0
src/core.c

@@ -1374,6 +1374,9 @@ const char *GetDirectoryPath(const char *fileName)
     memset(filePath, 0, 256);
     memset(filePath, 0, 256);
 
 
     lastSlash = strprbrk(fileName, "\\/");
     lastSlash = strprbrk(fileName, "\\/");
+    if (!lastSlash)
+        return NULL;
+
     strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1));
     strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1));
     filePath[strlen(fileName) - strlen(lastSlash)] = '\0';
     filePath[strlen(fileName) - strlen(lastSlash)] = '\0';