summaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2013-12-11 21:21:49 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-12-11 22:17:21 +0100
commit2c689964ab5578d7df1b77e4d19a8e02218163e4 (patch)
treeffeb5a31db3fab771c85693bb76985321f7c7640 /file.c
parent05b00742c6a8c90f42753bde3171d9fd70335238 (diff)
downloadsubsurface-2c689964ab5578d7df1b77e4d19a8e02218163e4.tar.gz
Don't use old pointer after realloc
If realloc moved the memory, we shouldn't try to access it. realloc copied that memory so access it via the new function instead. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'file.c')
-rw-r--r--file.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/file.c b/file.c
index 08c6a8309..9fd44d90f 100644
--- a/file.c
+++ b/file.c
@@ -117,12 +117,14 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, char
*/
buf = realloc(mem->buffer, mem->size + strlen("<csv></csv>"));
if (buf != NULL) {
- memmove(buf + 5, mem->buffer, mem->size);
+ memmove(buf + 5, buf, mem->size);
memcpy(buf, "<csv>", 5);
- memcpy(mem->buffer + mem->size + 5, "</csv>", 7);
- mem->buffer = buf;
+ memcpy(buf + mem->size + 5, "</csv>", 7);
mem->size += strlen("<csv></csv>");
+ mem->buffer = buf;
} else {
+ /* we can atleast try to strdup a error... */
+ *error = strdup("realloc failed in __func__\n");
free(mem->buffer);
return 1;
}