From aaa44b3c98db6508886b69c301021c38b3344a8a Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 24 Mar 2013 21:06:06 +0100 Subject: properly set errno --- fuzzy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'fuzzy.c') diff --git a/fuzzy.c b/fuzzy.c index c82d3c1..a9e6d4a 100644 --- a/fuzzy.c +++ b/fuzzy.c @@ -23,6 +23,7 @@ */ #include +#include #include #include #include @@ -112,6 +113,7 @@ struct fuzzy_state { /*@only@*/ /*@null@*/ struct fuzzy_state *fuzzy_new(void) { struct fuzzy_state *self; if(NULL == (self = malloc(sizeof(struct fuzzy_state)))) + /* malloc sets ENOMEM */ return NULL; self->bhstart = 0; self->bhend = 1; @@ -222,9 +224,11 @@ int fuzzy_digest(const struct fuzzy_state *self, /*@out@*/ char *result) { /* Initial blocksize guess. */ while((size_t)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self->total_size) { ++bi; - if(bi >= SSDEEP_BS(NUM_BLOCKHASHES)) + if(bi >= NUM_BLOCKHASHES) { /* The input exceeds data types. */ + errno = EOVERFLOW; return -1; + } } /* Adapt blocksize guess to actual digest length. */ while(bi >= self->bhend) @@ -235,6 +239,7 @@ int fuzzy_digest(const struct fuzzy_state *self, /*@out@*/ char *result) { i = snprintf(result, (size_t)remain, "%u:", SSDEEP_BS(bi)); if(i <= 0) + /* Maybe snprintf has set errno here? */ return -1; assert(i < remain); remain -= i; -- cgit v1.2.3