diff --git a/JSONparseCore.cpp b/JSONparseCore.cpp index 82f779c..1eee1ae 100644 --- a/JSONparseCore.cpp +++ b/JSONparseCore.cpp @@ -65,12 +65,25 @@ bool CJSONparse::WriteToScreen( const char * BasePath, const int Indent ) bool CJSONparse::WriteToFile( const char * BasePath, const char * Path, const char * FileName, const int Indent ) { - char FilePath[250] = ""; + char FilePath[250] = ""; + int PathLen = 0; + + // Validate + if (!FileName) { + Error = true; + sprintf( ErrorText, "No File name specified" ); + return false; + } // Build file name - if (Path) + if (Path && *Path) { strcpy( FilePath, Path ); - strcat( FilePath, FileName ); + PathLen = strlen( FilePath ); + if (FilePath[PathLen] != '/') { + FilePath[PathLen++] = '/'; + } + } + strcpy( &FilePath[PathLen], FileName ); // Read file return WriteToFile( BasePath, FilePath, Indent );