diff --git a/Makefile b/Makefile index 0876ee2..53c773f 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ # ################################################################ CFLAGS ?= -O3 -CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -Wstrict-aliasing=1 -pedantic +CFLAGS += -std=c99 -Wall -Wextra -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -Wstrict-aliasing=1 -Wswitch-enum -Wundef -pedantic FLAGS := $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(MOREFLAGS) @@ -89,7 +89,7 @@ sanitize: clean staticAnalyze: clean @echo ---- static analyzer - scan-build ---- - scan-build --status-bugs -v $(MAKE) all MOREFLAGS=-g + CFLAGS="-g -Werror" scan-build --status-bugs -v $(MAKE) all test-all: clean all test test32 armtest clangtest gpptest sanitize staticAnalyze diff --git a/xxhash.c b/xxhash.c index d33113f..2d8825c 100644 --- a/xxhash.c +++ b/xxhash.c @@ -372,10 +372,10 @@ XXH_PUBLIC_API unsigned int XXH32 (const void* input, size_t len, unsigned int s { #if 0 /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ - XXH32_state_t state; - XXH32_reset(&state, seed); - XXH32_update(&state, input, len); - return XXH32_digest(&state); + XXH32_CREATESTATE_STATIC(state); + XXH32_reset(state, seed); + XXH32_update(state, input, len); + return XXH32_digest(state); #else XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; @@ -512,10 +512,10 @@ XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned { #if 0 /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ - XXH64_state_t state; - XXH64_reset(&state, seed); - XXH64_update(&state, input, len); - return XXH64_digest(&state); + XXH64_CREATESTATE_STATIC(state); + XXH64_reset(state, seed); + XXH64_update(state, input, len); + return XXH64_digest(state); #else XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; diff --git a/xxhash.h b/xxhash.h index c287866..4c7f54b 100644 --- a/xxhash.h +++ b/xxhash.h @@ -168,12 +168,16 @@ XXH64() : /* **************************** * Advanced Hash Functions ******************************/ -typedef struct XXH32_state_s XXH32_state_t; /* incomplete */ -typedef struct XXH64_state_s XXH64_state_t; /* incomplete */ +typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */ +typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ -/*!Static allocation - For static linking only, do not use in the context of DLL ! */ +/*! Static allocation + For static linking only, do not use in the context of DLL ! + XXHnn_CREATESTATE_STATIC(name); + is static-allocation equivalent of : + XXHnn_state_t* name = XXHnn_createState(); +*/ typedef struct { long long ll[ 6]; } XXH32_stateBody_t; typedef struct { long long ll[11]; } XXH64_stateBody_t; diff --git a/xxhsum.c b/xxhsum.c index 887d2b1..5256f18 100644 --- a/xxhsum.c +++ b/xxhsum.c @@ -141,6 +141,8 @@ static const char author[] = "Yann Collet"; #define MAX_MEM (2 GB - 64 MB) static const char stdinName[] = "-"; +typedef enum { algo_xxh32, algo_xxh64 } algoType; +static const algoType g_defaultAlgo = algo_xxh64; /* required within main() & usage() */ /* ************************************ @@ -155,9 +157,8 @@ static unsigned g_displayLevel = 1; /* ************************************ * Local variables **************************************/ -static int g_nbIterations = NBLOOPS; -static int g_fn_selection = 1; /* required within main() & usage() */ static size_t g_sampleSize = 100 KB; +static int g_nbIterations = NBLOOPS; /* ************************************ @@ -495,6 +496,15 @@ static void BMK_sanityCheck(void) } +static void BMK_display_LittleEndian(const void* ptr, size_t length) +{ + const BYTE* p = (const BYTE*)ptr; + size_t index = BMK_isLittleEndian() ? 0 : length-1 ; + int incr = BMK_isLittleEndian() ? 1 : -1; + while (index 1) return badusage(exename); - if (filenamesStart==0) filenamesStart = argc; - return BMK_hashFiles(argv+filenamesStart, argc-filenamesStart, g_fn_selection); + return BMK_hashFiles(argv+filenamesStart, argc-filenamesStart, algo, displayEndianess); }