From 5b10b24044b3350a19ab3d3c0b37b5e9c12365b1 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 13 Mar 2016 23:54:56 +0100 Subject: Multiple changes: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) Compile test with -O0, it takes too long otherwise. 2) Add error codes: ZERROR_0_POW_0, ZERROR_0_DIV_0, ZERROR_DIV_0, ZERROR_NEGATIVE. 3) Add workaround for a bug in clang (src/allocator.c). 4) Cleanups. 5) Minor optimisations. 6) Add inclusion guard for zahl.h. Signed-off-by: Mattias Andrée --- zahl.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'zahl.h') diff --git a/zahl.h b/zahl.h index 89fc6f8..d051bc1 100644 --- a/zahl.h +++ b/zahl.h @@ -3,6 +3,9 @@ /* Warning: libzahl is not thread-safe. */ /* Caution: Do not use libzahl for cryptographic applications, use a specialised library. */ +#ifndef ZAHL_H +#define ZAHL_H + #include #include @@ -27,7 +30,11 @@ enum zranddev { FAST_RANDOM = 0, SECURE_RANDOM }; enum zranddist { QUASIUNIFORM = 0, UNIFORM }; enum zerror { - ZERROR_ERRNO_SET = 0 + ZERROR_ERRNO_SET = 0, /* Please refer to errno. */ + ZERROR_0_POW_0, /* Indeterminate form: 0:th power of 0. (Translatable to EDOM.) */ + ZERROR_0_DIV_0, /* Indeterminate form: 0 divided by 0. (Translatable to EDOM.) */ + ZERROR_DIV_0, /* Undefined result: Division by 0. (Translatable to EDOM.) */ + ZERROR_NEGATIVE /* Argument must be non-negative. (Translatable to EDOM or EINVAL.) */ }; @@ -160,7 +167,7 @@ zlsb(z_t a) return SIZE_MAX; for (; !a->chars[i]; i++); i *= 8 * sizeof(zahl_char_t); - i += __builtin_ctzll(a->chars[i]); + i += (size_t)__builtin_ctzll(a->chars[i]); return i; } #else @@ -190,7 +197,7 @@ zbits(z_t a) return 1; while (!a->chars[a->used - 1]) a->used--; /* TODO should not be necessary */ rc = a->used * 8 * sizeof(zahl_char_t); - rc -= __builtin_clzll(a->chars[a->used - 1]); + rc -= (size_t)__builtin_clzll(a->chars[a->used - 1]); return rc; } #else @@ -208,3 +215,6 @@ zbits(z_t a) return rc; } #endif + + +#endif -- cgit v1.2.3-70-g09d2