statdump: use standard I/O functions for buffering - bmf - bmf (Bayesian Mail F… | |
git clone git://git.codemadness.org/bmf | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit e39d60975a228c3d1e5b9512e082fb8bb1c28001 | |
parent 24fa4a0c3c143c6f36f1ca08b41135156c68f9ff | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Thu, 8 Nov 2018 18:12:36 +0100 | |
statdump: use standard I/O functions for buffering | |
+ fix undefined behaviour with tolower() and ugly sprintf() buffering. | |
Diffstat: | |
M filt.c | 24 +++++++----------------- | |
1 file changed, 7 insertions(+), 17 deletions(-) | |
--- | |
diff --git a/filt.c b/filt.c | |
@@ -22,31 +22,21 @@ | |
/* Dump the contents of a statistics structure */ | |
void | |
-statdump(stats_t * pstat, int fd) | |
+statdump(stats_t * pstat, FILE *fp) | |
{ | |
- char iobuf[IOBUFSIZE]; | |
- char *p; | |
discrim_t *pp; | |
+ size_t i; | |
- p = iobuf; | |
- p += sprintf(iobuf, "# Spamicity: %f\n", pstat->spamicity); | |
+ fprintf(fp, "# Spamicity: %f\n", pstat->spamicity); | |
for (pp = pstat->extrema; pp < pstat->extrema + pstat->keepers; pp++) { | |
if (pp->key.len) { | |
- strcpy(p, "# '"); | |
- p += 3; | |
- strncpylwr(p, pp->key.p, pp->key.len); | |
- p += pp->key.len; | |
- p += snprintf(p, 28, "' -> %f\n", pp->prob); | |
- if (p + MAXWORDLEN + 32 > (iobuf + 1)) { | |
- write(fd, iobuf, p - iobuf); | |
- p = iobuf; | |
- } | |
+ fprintf(fp, "# '"); | |
+ for (i = 0; i < pp->key.len; i++) | |
+ fputc(tolower((unsigned char)pp->key.p[i]), fp… | |
+ fprintf(fp, "' -> %f\n", pp->prob); | |
} | |
} | |
- if (p != iobuf) { | |
- write(fd, iobuf, p - iobuf); | |
- } | |
} | |
void |