Fix potential underflow in item counting - sacc - sacc(omys), simple console gopher client
(HTM) git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/sacc/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) LICENSE
---
(DIR) commit b1d593674e9619d39191b87c769d8caf9723bc0e
(DIR) parent 1eb587973e37752fdbd96dae505ba298d813dce5
(HTM) Author: Quentin Rameau <quinq@fifth.space>
Date: Fri, 23 Jun 2017 20:56:47 +0200
Fix potential underflow in item counting
Diffstat:
M sacc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/sacc.c b/sacc.c
@@ -262,9 +262,11 @@ molddiritem(char *raw)
for (crlf = raw, nitems = 0; p = strstr(crlf, "\r\n"); ++nitems)
crlf = p+2;
- if (--nitems < 1)
+ if (nitems <= 1)
return NULL;
- if (strcmp(crlf-3, ".\r\n"))
+ if (!strcmp(crlf-3, ".\r\n"))
+ --nitems;
+ else
fprintf(stderr, "Parsing error: missing .\\r\\n last line\n");
dir = xmalloc(sizeof(Dir));