Fix more &vec[0] problems

This commit is contained in:
Tamás Bálint Misius 2024-04-13 22:32:37 +02:00
parent 73daf67c34
commit 58c0ab4747
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 6 additions and 1 deletions

View File

@ -58,7 +58,7 @@ bool ReadFile(std::vector<char> &fileData, ByteString filename)
if (f) f.seekg(0, std::ios::end);
if (f) fileData.resize(f.tellg());
if (f) f.seekg(0);
if (f) f.read(&fileData[0], fileData.size());
if (f && fileData.size()) f.read(&fileData[0], fileData.size());
if (!f)
{
std::cerr << "ReadFile: " << filename << ": " << strerror(errno) << std::endl;

View File

@ -20,6 +20,11 @@ void Prefs::Read()
Json::CharReaderBuilder rbuilder;
std::unique_ptr<Json::CharReader> const reader(rbuilder.newCharReader());
ByteString errs;
if (!data.size())
{
std::cerr << "no json data" << std::endl;
return;
}
if (!reader->parse(&data[0], &data[0] + data.size(), &root, &errs))
{
std::cerr << errs << std::endl;