Fix abort: Invalid buffer size, exiting.
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
With some malformed messages, bogolexer aborts with: Invalid buffer size, exiting.
Attached is a minimized example input.
This patch eliminates the abort in this case:
--- a/src/fgetsl.c
+++ b/src/fgetsl.c
@@ -26,6 +26,9 @@ int xfgetsl(char *buf, int max_size, FILE *in, bool no_nul_terminate)
char *end = buf + max_size; /* Physical end of buffer */
char *fin = end - (no_nul_terminate ? 0 : 1); /* Last available byte */
+ if (cp == fin && no_nul_terminate)
+ return 0;
+
if (cp >= fin) {
fprintf(stderr, "Invalid buffer size, exiting.\n");
abort();
committed to Git, c03bd8dd83daedf0215b94694827118a8a730b5f