Null terminate buffer at the correct spot

fread tells us how many bytes it read.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-03-05 18:30:52 -08:00
parent e1a1c218c4
commit 4f4fff3917

View file

@ -159,7 +159,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
rewind(f);
membuf = (char *)malloc(streamsize + 1);
if (!membuf || !fread(membuf, streamsize, 1, f)) {
if (!membuf || (streamsize = fread(membuf, streamsize, 1, f)) == 0) {
*errorMsg = tr("internal error: %1").arg(qt_error_string());
fclose(f);
free((void *)membuf);