Fix buffer underrun found with address sanitizer

When subpath is the empty string, the code was reading from subPath[-1]
This commit is contained in:
Ben Payne 2015-03-04 15:46:07 -05:00
parent 74a05854d5
commit eabff49a6a

View file

@ -1306,8 +1306,10 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve
// Compose our search string - Format : ([path]/[subpath]/*)
//-----------------------------------------------------------------------------
char trail = basePath[ dStrlen(basePath) - 1 ];
char subTrail = subPath ? subPath[ dStrlen(subPath) - 1 ] : '\0';
dsize_t trLen = basePath ? dStrlen(basePath) : 0;
dsize_t subtrLen = subPath ? dStrlen(subPath) : 0;
char trail = trLen > 0 ? basePath[ trLen - 1 ] : '\0';
char subTrail = subtrLen > 0 ? subPath[ subtrLen - 1 ] : '\0';
if( trail == '/' )
{