properly set errno
authorHelmut Grohne <helmut@subdivi.de>
Sun, 24 Mar 2013 20:06:06 +0000 (21:06 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Sun, 24 Mar 2013 20:06:06 +0000 (21:06 +0100)
fuzzy.c

diff --git a/fuzzy.c b/fuzzy.c
index c82d3c1..a9e6d4a 100644 (file)
--- a/fuzzy.c
+++ b/fuzzy.c
@@ -23,6 +23,7 @@
  */
 
 #include <assert.h>
  */
 
 #include <assert.h>
+#include <errno.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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))))
 /*@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;
                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;
        /* 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. */
                        /* The input exceeds data types. */
+                       errno = EOVERFLOW;
                        return -1;
                        return -1;
+               }
        }
        /* Adapt blocksize guess to actual digest length. */
        while(bi >= self->bhend)
        }
        /* 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)
 
        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;
                return -1;
        assert(i < remain);
        remain -= i;