(libretrodb) Return the correct str/buf length in rmsgpack_read and read_buff

This commit is contained in:
Higor Eurípedes 2015-11-14 15:39:40 -03:00
parent eb7b46c7c1
commit 6454f70c8d

View File

@ -458,16 +458,21 @@ error:
static int read_buff(RFILE *fd, size_t size, char **pbuff, uint64_t *len)
{
uint64_t tmp_len = 0;
ssize_t read_len = 0;
if (read_uint(fd, &tmp_len, size) == -1)
return -errno;
*pbuff = (char *)calloc((size_t)(tmp_len + 1), sizeof(char));
*pbuff = (char *)malloc((size_t)(tmp_len + 1) * sizeof(char));
if (retro_fread(fd, *pbuff, (size_t)tmp_len) == -1)
if ((read_len = retro_fread(fd, *pbuff, (size_t)tmp_len)) == -1)
goto error;
*len = tmp_len;
*len = read_len;
(*pbuff)[read_len] = 0;
/* Throw warning on read_len != tmp_len ? */
return 0;
error:
@ -562,7 +567,7 @@ int rmsgpack_read(RFILE *fd,
free(buff);
return 0;
}
return callbacks->read_string(buff, (uint32_t)tmp_len, data);
return callbacks->read_string(buff, (uint32_t)read_len, data);
}
else if (type > MPF_MAP32)
{