Navigation Menu

Skip to content

Commit

Permalink
append trailing zero to memory buffer, to allow safe use as char* (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke authored and sloretz committed Oct 29, 2018
1 parent a90a5e6 commit 42a5257
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/retriever.cpp
Expand Up @@ -137,8 +137,9 @@ MemoryResource Retriever::get(const std::string& url)
else if (!buf.v.empty())
{
res.size = buf.v.size();
res.data.reset(new uint8_t[res.size]);
res.data.reset(new uint8_t[res.size+1]);
memcpy(res.data.get(), &buf.v[0], res.size);
res.data[res.size] = '\0'; // write trailing zero for interpretation as char*
}

return res;
Expand Down

0 comments on commit 42a5257

Please sign in to comment.