From 29c6d03dfa1d8b5017e5d97006d258a73a0fd85e Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sat, 24 Jan 2015 17:03:11 +0200 Subject: [PATCH] Fix a bug if CSV file does not have ending new line Add a new line when importing a CSV file, so we get the last dive imported as well (in case file ends without last new line). See #814 Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/file.c b/file.c index cbe38ebae..eacd8756a 100644 --- a/file.c +++ b/file.c @@ -116,13 +116,13 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons * * Tag markers take: strlen("<>") = 5 */ - buf = realloc(mem->buffer, mem->size + 6 + strlen(tag) * 2); + buf = realloc(mem->buffer, mem->size + 7 + strlen(tag) * 2); if (buf != NULL) { char *starttag = NULL; char *endtag = NULL; starttag = malloc(3 + strlen(tag)); - endtag = malloc(4 + strlen(tag)); + endtag = malloc(5 + strlen(tag)); if (starttag == NULL || endtag == NULL) { /* this is fairly silly - so the malloc fails, but we strdup the error? @@ -135,12 +135,12 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons } sprintf(starttag, "<%s>", tag); - sprintf(endtag, "", tag); + sprintf(endtag, "\n", tag); memmove(buf + 2 + strlen(tag), buf, mem->size); memcpy(buf, starttag, 2 + strlen(tag)); - memcpy(buf + mem->size + 2 + strlen(tag), endtag, 4 + strlen(tag)); - mem->size += (5 + 2 * strlen(tag)); + memcpy(buf + mem->size + 2 + strlen(tag), endtag, 5 + strlen(tag)); + mem->size += (6 + 2 * strlen(tag)); mem->buffer = buf; free(starttag);