Introduction
Introduction Statistics Contact Development Disclaimer Help
fix buffer size calculation - ploot - simple plotting tools
git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65…
Log
Files
Refs
Tags
README
LICENSE
---
commit c9c242228362e465b83fc106675981fd45419228
parent b22b1b174646f828a28144c010961a9c57f54dbd
Author: Josuah Demangeon <[email protected]>
Date: Wed, 2 May 2018 05:09:18 +0200
fix buffer size calculation
Diffstat:
M main.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/main.c b/main.c
@@ -78,14 +78,15 @@ eatol(char *str)
}
void
-add_value(double **v, int *bufsiz, int nval, char *field)
+add_value(Vlist *v, int *bufsiz, int nval, char *field)
{
if (nval >= *bufsiz) {
- *bufsiz *= 2;
- if ((*v = realloc(*v, *bufsiz)) == NULL)
+ *bufsiz = *bufsiz * 2 + 1;
+ if ((v->v = realloc(v->v, *bufsiz)) == NULL)
perror("reallocating values buffer"), exit(1);
}
- (*v)[nval] = eatol(field);
+ v->v[nval] = eatol(field);
+ v->n = nval;
}
/*
@@ -106,7 +107,7 @@ add_each_value(Vlist *v, int *bufsiz, int ncol, int nval, c…
for (n = 0; (field = strsep(&line, ",")) != NULL; n++, v++) {
if (n > ncol)
fprintf(stderr, "%d: too many fields\n", nval), exit(0…
- add_value(&v->v, bufsiz, nval, field);
+ add_value(v, bufsiz, nval, field);
}
if (n < ncol)
fprintf(stderr, "%d: too few fields\n", nval), exit(0);
@@ -121,15 +122,15 @@ add_each_value(Vlist *v, int *bufsiz, int ncol, int nval,…
void
read_values(Vlist *v, int ncol)
{
- int n, nval, bufsiz;
+ int nval, bufsiz;
char line[LINE_MAX];
+ bufsiz = 0;
for (nval = 0; fgets(line, sizeof(line), stdin); nval++) {
estriplf(line);
add_each_value(v, &bufsiz, ncol, nval, line);
}
- for (n = 0; n < ncol; n++, v++)
- v->n = nval;
+ fprintf(stderr, "nval: %d, bufsiz: %d\n", nval, bufsiz), fflush(stderr…
}
static void
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.