Skip to content
Snippets Groups Projects
Commit e3bda576 authored by fireice-uk's avatar fireice-uk
Browse files

Fix for BOM addition in some text editors

parent c21b3d08
No related branches found
No related tags found
No related merge requests found
...@@ -209,9 +209,13 @@ bool jconf::parse_config(const char* sFilename) ...@@ -209,9 +209,13 @@ bool jconf::parse_config(const char* sFilename)
return false; return false;
} }
buffer = (char*)malloc(flen + 3); if(flen <= 16)
{
printer::inst()->print_msg(L0, "File is empty or too short - %s.", sFilename);
return false;
}
buffer[0] = '{'; buffer = (char*)malloc(flen + 3);
if(fread(buffer+1, flen, 1, pFile) != 1) if(fread(buffer+1, flen, 1, pFile) != 1)
{ {
free(buffer); free(buffer);
...@@ -219,9 +223,19 @@ bool jconf::parse_config(const char* sFilename) ...@@ -219,9 +223,19 @@ bool jconf::parse_config(const char* sFilename)
printer::inst()->print_msg(L0, "Read error while reading %s.", sFilename); printer::inst()->print_msg(L0, "Read error while reading %s.", sFilename);
return false; return false;
} }
fclose(pFile);
//Replace Unicode BOM with spaces - we always use UTF-8
if(buffer[1] == 0xEF && buffer[2] == 0xBB && buffer[3] == 0xBF)
{
buffer[1] = ' ';
buffer[2] = ' ';
buffer[3] = ' ';
}
buffer[0] = '{';
buffer[flen] = '}'; buffer[flen] = '}';
buffer[flen + 1] = '\0'; buffer[flen + 1] = '\0';
fclose(pFile);
prv->jsonDoc.Parse<kParseCommentsFlag|kParseTrailingCommasFlag>(buffer, flen+2); prv->jsonDoc.Parse<kParseCommentsFlag|kParseTrailingCommasFlag>(buffer, flen+2);
free(buffer); free(buffer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment