parent
b2ff22ee54
commit
b482ffa6a6
18
misc/nstat.c
18
misc/nstat.c
|
|
@ -121,14 +121,16 @@ void load_good_table(FILE *fp)
|
||||||
int nr;
|
int nr;
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
double rate;
|
double rate;
|
||||||
char idbuf[256];
|
char idbuf[sizeof(buf)];
|
||||||
if (buf[0] == '#') {
|
if (buf[0] == '#') {
|
||||||
buf[strlen(buf)-1] = 0;
|
buf[strlen(buf)-1] = 0;
|
||||||
if (info_source[0] && strcmp(info_source, buf+1))
|
if (info_source[0] && strcmp(info_source, buf+1))
|
||||||
source_mismatch = 1;
|
source_mismatch = 1;
|
||||||
strncpy(info_source, buf+1, sizeof(info_source)-1);
|
info_source[0] = 0;
|
||||||
|
strncat(info_source, buf+1, sizeof(info_source)-1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/* idbuf is as big as buf, so this is safe */
|
||||||
nr = sscanf(buf, "%s%llu%lg", idbuf, &val, &rate);
|
nr = sscanf(buf, "%s%llu%lg", idbuf, &val, &rate);
|
||||||
if (nr < 2)
|
if (nr < 2)
|
||||||
abort();
|
abort();
|
||||||
|
|
@ -162,7 +164,7 @@ void load_ugly_table(FILE *fp)
|
||||||
struct nstat_ent *n;
|
struct nstat_ent *n;
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
char idbuf[256];
|
char idbuf[sizeof(buf)];
|
||||||
int off;
|
int off;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
|
@ -170,8 +172,9 @@ void load_ugly_table(FILE *fp)
|
||||||
if (!p)
|
if (!p)
|
||||||
abort();
|
abort();
|
||||||
*p = 0;
|
*p = 0;
|
||||||
strcpy(idbuf, buf);
|
idbuf[0] = 0;
|
||||||
off = strlen(idbuf);
|
strncat(idbuf, buf, sizeof(idbuf) - 1);
|
||||||
|
off = p - buf;
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
|
|
@ -180,7 +183,10 @@ void load_ugly_table(FILE *fp)
|
||||||
*next++ = 0;
|
*next++ = 0;
|
||||||
else if ((next = strchr(p, '\n')) != NULL)
|
else if ((next = strchr(p, '\n')) != NULL)
|
||||||
*next++ = 0;
|
*next++ = 0;
|
||||||
strcpy(idbuf+off, p);
|
if (off < sizeof(idbuf)) {
|
||||||
|
idbuf[off] = 0;
|
||||||
|
strncat(idbuf, p, sizeof(idbuf) - off - 1);
|
||||||
|
}
|
||||||
n = malloc(sizeof(*n));
|
n = malloc(sizeof(*n));
|
||||||
if (!n)
|
if (!n)
|
||||||
abort();
|
abort();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue