fix label length due to sizeof(ptr) misuse - ploot - simple plotting tools
(HTM) git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ploot
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 7dad2b0d2e8a560efbe5d38164a63f999b3a23f9
(DIR) parent ca79681acc3c649b67abc21bc0aabe980d5c989c
(HTM) Author: Josuah Demangeon <me@josuah.net>
Date: Sun, 23 Feb 2020 11:58:08 +0100
fix label length due to sizeof(ptr) misuse
Diffstat:
M src/csv.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/src/csv.c b/src/csv.c
@@ -69,7 +69,8 @@ csv_addrow(struct csv *vl, size_t ncol, char *line)
void
csv_labels(FILE *fp, struct csv **vl, size_t *ncol)
{
- char *field, *line, *cp, *label;
+ char *field, *line, *cp;
+ struct csv *col;
size_t sz;
ssize_t r;
@@ -79,6 +80,7 @@ csv_labels(FILE *fp, struct csv **vl, size_t *ncol)
fatal(111, "error while reading from file");
if (r == -1)
fatal(100, "missing label line");
+ strchomp(line);
cp = line;
if (strcmp(strsep(&cp, ","), "epoch") != 0)
@@ -88,8 +90,8 @@ csv_labels(FILE *fp, struct csv **vl, size_t *ncol)
*ncol = 0;
while ((field = strsep(&cp, ","))) {
assert(*vl = realloc(*vl, sz += sizeof(**vl)));
- label = (*vl)[(*ncol)++].label;
- strlcpy(label, field, sizeof(label));
+ col = (*vl) + (*ncol)++;
+ strlcpy(col->label, field, sizeof(col->label));
}
free(line);