From 706cd9caf6222bf1b0377166679e74970153e1bb Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Thu, 22 Jun 2017 17:21:28 +0200 Subject: [PATCH] Bug fix: - Validate File Path and add '/' when saving JSON file --- JSONparseCore.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 );