mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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 <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6bb1fee9a6
commit
29c6d03dfa
1 changed files with 5 additions and 5 deletions
10
file.c
10
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, "</%s>", tag);
|
||||
sprintf(endtag, "\n</%s>", 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);
|
||||
|
|
Loading…
Reference in a new issue