fixed : clang warnings
authorYann Collet <yann.collet.73@gmail.com>
Mon, 22 Sep 2014 17:42:00 +0000 (18:42 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 22 Sep 2014 17:42:00 +0000 (18:42 +0100)
examples/blockStreaming_doubleBuffer.c
examples/blockStreaming_lineByLine.c
examples/blockStreaming_ringBuffer.c
lz4frame.c
programs/frametest.c
programs/lz4cli.c

index bd87e77..0adf6ae 100644 (file)
@@ -140,9 +140,9 @@ int main(int argc, char* argv[])
         return 0;
     }
 
-    sprintf(inpFilename, "%s", argv[1]);
-    sprintf(lz4Filename, "%s.lz4s-%d", argv[1], BLOCK_BYTES);
-    sprintf(decFilename, "%s.lz4s-%d.dec", argv[1], BLOCK_BYTES);
+    snprintf(inpFilename, 256, "%s", argv[1]);
+    snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[1], BLOCK_BYTES);
+    snprintf(decFilename, 256, "%s.lz4s-%d.dec", argv[1], BLOCK_BYTES);
 
     printf("inp = [%s]\n", inpFilename);
     printf("lz4 = [%s]\n", lz4Filename);
index e236a44..6d14801 100644 (file)
@@ -158,9 +158,9 @@ int main(int argc, char* argv[])
         return 0;
     }
 
-    sprintf(inpFilename, "%s", argv[1]);
-    sprintf(lz4Filename, "%s.lz4s", argv[1]);
-    sprintf(decFilename, "%s.lz4s.dec", argv[1]);
+    snprintf(inpFilename, 256, "%s", argv[1]);
+    snprintf(lz4Filename, 256, "%s.lz4s", argv[1]);
+    snprintf(decFilename, 256, "%s.lz4s.dec", argv[1]);
 
     printf("inp = [%s]\n", inpFilename);
     printf("lz4 = [%s]\n", lz4Filename);
index 725e375..bfdbed1 100644 (file)
@@ -136,9 +136,9 @@ int main(int argc, char** argv)
         return 0;
     }
 
-    sprintf(inpFilename, "%s", argv[1]);
-    sprintf(lz4Filename, "%s.lz4s-%d", argv[1], 0);
-    sprintf(decFilename, "%s.lz4s-%d.dec", argv[1], 0);
+    snprintf(inpFilename, 256, "%s", argv[1]);
+    snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[1], 0);
+    snprintf(decFilename, 256, "%s.lz4s-%d.dec", argv[1], 0);
 
     printf("inp = [%s]\n", inpFilename);
     printf("lz4 = [%s]\n", lz4Filename);
index 35e5b0b..3a750c0 100644 (file)
 **************************************/
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)   /* C99 */
 # include <stdint.h>
-  typedef  uint8_t BYTE;
-  typedef uint16_t U16;
-  typedef uint32_t U32;
-  typedef  int32_t S32;
-  typedef uint64_t U64;
+typedef  uint8_t BYTE;
+typedef uint16_t U16;
+typedef uint32_t U32;
+typedef  int32_t S32;
+typedef uint64_t U64;
 #else
-  typedef unsigned char       BYTE;
-  typedef unsigned short      U16;
-  typedef unsigned int        U32;
-  typedef   signed int        S32;
-  typedef unsigned long long  U64;
+typedef unsigned char       BYTE;
+typedef unsigned short      U16;
+typedef unsigned int        U32;
+typedef   signed int        S32;
+typedef unsigned long long  U64;
 #endif
 
 
 /**************************************
    Structures and local types
 **************************************/
-typedef struct {
-       LZ4F_preferences_t prefs;
-       unsigned version;
-       unsigned cStage;
-       size_t maxBlockSize;
-       size_t maxBufferSize;
-       BYTE*  tmpBuff;
-       BYTE*  tmpIn;
-       size_t tmpInSize;
-       XXH32_stateSpace_t xxh;
-       LZ4_stream_t lz4ctx;
+typedef struct
+{
+    LZ4F_preferences_t prefs;
+    unsigned version;
+    unsigned cStage;
+    size_t maxBlockSize;
+    size_t maxBufferSize;
+    BYTE*  tmpBuff;
+    BYTE*  tmpIn;
+    size_t tmpInSize;
+    XXH32_stateSpace_t xxh;
+    LZ4_stream_t lz4ctx;
 } LZ4F_cctx_internal_t;
 
-typedef struct {
+typedef struct
+{
     LZ4F_frameInfo_t frameInfo;
-       unsigned version;
-       unsigned dStage;
-       size_t maxBlockSize;
-       size_t maxBufferSize;
-       const BYTE* srcExpect;
-       BYTE*  tmpIn;
-       size_t tmpInSize;
-       size_t tmpInTarget;
-       BYTE*  tmpOutBuffer;
-       BYTE*  dict;
-       size_t dictSize;
-       BYTE*  tmpOut;
-       size_t tmpOutSize;
-       size_t tmpOutStart;
-       XXH32_stateSpace_t xxh;
-       BYTE   header[8];
+    unsigned version;
+    unsigned dStage;
+    size_t maxBlockSize;
+    size_t maxBufferSize;
+    const BYTE* srcExpect;
+    BYTE*  tmpIn;
+    size_t tmpInSize;
+    size_t tmpInTarget;
+    BYTE*  tmpOutBuffer;
+    BYTE*  dict;
+    size_t dictSize;
+    BYTE*  tmpOut;
+    size_t tmpOutSize;
+    size_t tmpOutStart;
+    XXH32_stateSpace_t xxh;
+    BYTE   header[8];
 } LZ4F_dctx_internal_t;
 
 
@@ -171,7 +173,7 @@ typedef enum { OK_NoError=0, ERROR_GENERIC = 1,
 
 int LZ4F_isError(LZ4F_errorCode_t code)
 {
-       return (code > (LZ4F_errorCode_t)(-ERROR_maxCode));
+    return (code > (LZ4F_errorCode_t)(-ERROR_maxCode));
 }
 
 const char* LZ4F_getErrorName(LZ4F_errorCode_t code)
@@ -187,22 +189,22 @@ const char* LZ4F_getErrorName(LZ4F_errorCode_t code)
 **************************************/
 static size_t LZ4F_getBlockSize(unsigned blockSizeID)
 {
-       static const size_t blockSizes[4] = { 64 KB, 256 KB, 1 MB, 4 MB };
+    static const size_t blockSizes[4] = { 64 KB, 256 KB, 1 MB, 4 MB };
 
-       if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
-       blockSizeID -= 4;
-       if (blockSizeID > 3) return (size_t)-ERROR_maxBlockSize_invalid;
-       return blockSizes[blockSizeID];
+    if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
+    blockSizeID -= 4;
+    if (blockSizeID > 3) return (size_t)-ERROR_maxBlockSize_invalid;
+    return blockSizes[blockSizeID];
 }
 
 
 /* unoptimized version; solves endianess & alignment issues */
 static void LZ4F_writeLE32 (BYTE* dstPtr, U32 value32)
 {
-       dstPtr[0] = (BYTE)value32;
-       dstPtr[1] = (BYTE)(value32 >> 8);
-       dstPtr[2] = (BYTE)(value32 >> 16);
-       dstPtr[3] = (BYTE)(value32 >> 24);
+    dstPtr[0] = (BYTE)value32;
+    dstPtr[1] = (BYTE)(value32 >> 8);
+    dstPtr[2] = (BYTE)(value32 >> 16);
+    dstPtr[3] = (BYTE)(value32 >> 24);
 }
 
 static U32 LZ4F_readLE32 (const BYTE* srcPtr)
@@ -217,8 +219,8 @@ static U32 LZ4F_readLE32 (const BYTE* srcPtr)
 
 static BYTE LZ4F_headerChecksum (const BYTE* header, size_t length)
 {
-       U32 xxh = XXH32(header, (U32)length, 0);
-       return (BYTE)(xxh >> 8);
+    U32 xxh = XXH32(header, (U32)length, 0);
+    return (BYTE)(xxh >> 8);
 }
 
 
@@ -227,17 +229,17 @@ static BYTE LZ4F_headerChecksum (const BYTE* header, size_t length)
 **************************************/
 size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
 {
-       LZ4F_preferences_t prefs = { 0 };
-       size_t headerSize;
-       size_t streamSize;
+    LZ4F_preferences_t prefs = { 0 };
+    size_t headerSize;
+    size_t streamSize;
 
-       if (preferencesPtr!=NULL) prefs = *preferencesPtr;
-       prefs.autoFlush = 1;
+    if (preferencesPtr!=NULL) prefs = *preferencesPtr;
+    prefs.autoFlush = 1;
 
-       headerSize = 7;      /* basic header size (no option) including magic number */
-       streamSize = LZ4F_compressBound(srcSize, &prefs);
+    headerSize = 7;      /* basic header size (no option) including magic number */
+    streamSize = LZ4F_compressBound(srcSize, &prefs);
 
-       return headerSize + streamSize;
+    return headerSize + streamSize;
 }
 
 
@@ -254,11 +256,11 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
 {
     LZ4F_cctx_internal_t cctxI = { 0 };   /* works because no allocation */
     LZ4F_preferences_t prefs = { 0 };
-       LZ4F_compressOptions_t options = { 0 };
-       LZ4F_errorCode_t errorCode;
-       BYTE* const dstStart = (BYTE*) dstBuffer;
-       BYTE* dstPtr = dstStart;
-       BYTE* const dstEnd = dstStart + dstMaxSize;
+    LZ4F_compressOptions_t options = { 0 };
+    LZ4F_errorCode_t errorCode;
+    BYTE* const dstStart = (BYTE*) dstBuffer;
+    BYTE* dstPtr = dstStart;
+    BYTE* const dstEnd = dstStart + dstMaxSize;
 
 
     cctxI.version = LZ4F_VERSION;
@@ -285,23 +287,23 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
 
     options.stableSrc = 1;
 
-       if (dstMaxSize < LZ4F_compressFrameBound(srcSize, &prefs))
-               return (size_t)-ERROR_dstMaxSize_tooSmall;
+    if (dstMaxSize < LZ4F_compressFrameBound(srcSize, &prefs))
+        return (size_t)-ERROR_dstMaxSize_tooSmall;
 
-       errorCode = LZ4F_compressBegin(&cctxI, dstBuffer, dstMaxSize, &prefs);  /* write header */
-       if (LZ4F_isError(errorCode)) return errorCode;
-       dstPtr += errorCode;   /* header size */
+    errorCode = LZ4F_compressBegin(&cctxI, dstBuffer, dstMaxSize, &prefs);  /* write header */
+    if (LZ4F_isError(errorCode)) return errorCode;
+    dstPtr += errorCode;   /* header size */
 
-       dstMaxSize -= errorCode;
+    dstMaxSize -= errorCode;
     errorCode = LZ4F_compressUpdate(&cctxI, dstPtr, dstMaxSize, srcBuffer, srcSize, &options);
-       if (LZ4F_isError(errorCode)) return errorCode;
-       dstPtr += errorCode;
+    if (LZ4F_isError(errorCode)) return errorCode;
+    dstPtr += errorCode;
 
-       errorCode = LZ4F_compressEnd(&cctxI, dstPtr, dstEnd-dstPtr, &options);   /* flush last block, and generate suffix */
-       if (LZ4F_isError(errorCode)) return errorCode;
-       dstPtr += errorCode;
+    errorCode = LZ4F_compressEnd(&cctxI, dstPtr, dstEnd-dstPtr, &options);   /* flush last block, and generate suffix */
+    if (LZ4F_isError(errorCode)) return errorCode;
+    dstPtr += errorCode;
 
-       return (dstPtr - dstStart);
+    return (dstPtr - dstStart);
 }
 
 
@@ -319,28 +321,28 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
  */
 LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_compressionContext_t* LZ4F_compressionContextPtr, unsigned version)
 {
-       LZ4F_cctx_internal_t* cctxPtr;
+    LZ4F_cctx_internal_t* cctxPtr;
 
-       cctxPtr = ALLOCATOR(sizeof(LZ4F_cctx_internal_t));
-       if (cctxPtr==NULL) return (LZ4F_errorCode_t)-ERROR_allocation_failed;
+    cctxPtr = ALLOCATOR(sizeof(LZ4F_cctx_internal_t));
+    if (cctxPtr==NULL) return (LZ4F_errorCode_t)-ERROR_allocation_failed;
 
-       cctxPtr->version = version;
-       cctxPtr->cStage = 0;   /* Next stage : write header */
+    cctxPtr->version = version;
+    cctxPtr->cStage = 0;   /* Next stage : write header */
 
-       *LZ4F_compressionContextPtr = (LZ4F_compressionContext_t)cctxPtr;
+    *LZ4F_compressionContextPtr = (LZ4F_compressionContext_t)cctxPtr;
 
-       return OK_NoError;
+    return OK_NoError;
 }
 
 
 LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_compressionContext)
 {
-       LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)LZ4F_compressionContext;
+    LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)LZ4F_compressionContext;
 
-       FREEMEM(cctxPtr->tmpBuff);
-       FREEMEM(LZ4F_compressionContext);
+    FREEMEM(cctxPtr->tmpBuff);
+    FREEMEM(LZ4F_compressionContext);
 
-       return OK_NoError;
+    return OK_NoError;
 }
 
 
@@ -353,26 +355,26 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_comp
 size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_preferences_t* preferencesPtr)
 {
     LZ4F_preferences_t prefNull = { 0 };
-       LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
-       BYTE* const dstStart = (BYTE*)dstBuffer;
-       BYTE* dstPtr = dstStart;
-       BYTE* headerStart;
-       size_t requiredBuffSize;
-
-       if (dstMaxSize < LZ4F_MAXHEADERFRAME_SIZE) return (size_t)-ERROR_dstMaxSize_tooSmall;
-       if (cctxPtr->cStage != 0) return (size_t)-ERROR_GENERIC;
-       if (preferencesPtr == NULL) preferencesPtr = &prefNull;
-
-       /* Buffer Management */
-       cctxPtr->prefs = *preferencesPtr;
-       if (cctxPtr->prefs.frameInfo.blockSizeID == 0) cctxPtr->prefs.frameInfo.blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
-       cctxPtr->maxBlockSize = LZ4F_getBlockSize(cctxPtr->prefs.frameInfo.blockSizeID);
-
-       requiredBuffSize = cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == blockLinked) * 128 KB);
-       if (preferencesPtr->autoFlush)
+    LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
+    BYTE* const dstStart = (BYTE*)dstBuffer;
+    BYTE* dstPtr = dstStart;
+    BYTE* headerStart;
+    size_t requiredBuffSize;
+
+    if (dstMaxSize < LZ4F_MAXHEADERFRAME_SIZE) return (size_t)-ERROR_dstMaxSize_tooSmall;
+    if (cctxPtr->cStage != 0) return (size_t)-ERROR_GENERIC;
+    if (preferencesPtr == NULL) preferencesPtr = &prefNull;
+
+    /* Buffer Management */
+    cctxPtr->prefs = *preferencesPtr;
+    if (cctxPtr->prefs.frameInfo.blockSizeID == 0) cctxPtr->prefs.frameInfo.blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
+    cctxPtr->maxBlockSize = LZ4F_getBlockSize(cctxPtr->prefs.frameInfo.blockSizeID);
+
+    requiredBuffSize = cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == blockLinked) * 128 KB);
+    if (preferencesPtr->autoFlush)
         requiredBuffSize = (cctxPtr->prefs.frameInfo.blockMode == blockLinked) * 64 KB;   /* just needs dict */
 
-       if (cctxPtr->maxBufferSize < requiredBuffSize)
+    if (cctxPtr->maxBufferSize < requiredBuffSize)
     {
         cctxPtr->maxBufferSize = requiredBuffSize;
         FREEMEM(cctxPtr->tmpBuff);
@@ -381,27 +383,27 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
     }
     cctxPtr->tmpIn = cctxPtr->tmpBuff;
     cctxPtr->tmpInSize = 0;
-       XXH32_resetState(&(cctxPtr->xxh), 0);
-       LZ4_resetStream(&(cctxPtr->lz4ctx));
+    XXH32_resetState(&(cctxPtr->xxh), 0);
+    LZ4_resetStream(&(cctxPtr->lz4ctx));
 
-       /* Magic Number */
-       LZ4F_writeLE32(dstPtr, LZ4F_MAGICNUMBER);
-       dstPtr += 4;
-       headerStart = dstPtr;
+    /* Magic Number */
+    LZ4F_writeLE32(dstPtr, LZ4F_MAGICNUMBER);
+    dstPtr += 4;
+    headerStart = dstPtr;
 
-       /* FLG Byte */
-       //cctxPtr->prefs.frameInfo.blockMode = 1;   // <============ debug
+    /* FLG Byte */
+    //cctxPtr->prefs.frameInfo.blockMode = 1;   // <============ debug
     *dstPtr++ = ((1 & _2BITS) << 6)    /* Version('01') */
-              + ((cctxPtr->prefs.frameInfo.blockMode & _1BIT ) << 5)    /* Block mode */
-              + (char)((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2);   /* Stream checksum */
-       /* BD Byte */
+                + ((cctxPtr->prefs.frameInfo.blockMode & _1BIT ) << 5)    /* Block mode */
+                + (char)((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2);   /* Stream checksum */
+    /* BD Byte */
     *dstPtr++ = (char)((cctxPtr->prefs.frameInfo.blockSizeID & _3BITS) << 4);
-       /* CRC Byte */
-       *dstPtr++ = LZ4F_headerChecksum(headerStart, 2);
+    /* CRC Byte */
+    *dstPtr++ = LZ4F_headerChecksum(headerStart, 2);
 
-       cctxPtr->cStage = 1;   /* header written, wait for data block */
+    cctxPtr->cStage = 1;   /* header written, wait for data block */
 
-       return (dstPtr - dstStart);
+    return (dstPtr - dstStart);
 }
 
 
@@ -412,15 +414,15 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
 size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
 {
     LZ4F_frameInfo_t* frameInfoPtr = (LZ4F_frameInfo_t*)preferencesPtr;   /* works because prefs starts with frameInfo */
-       blockSizeID_t bid = (frameInfoPtr==NULL) ? LZ4F_BLOCKSIZEID_DEFAULT : frameInfoPtr->blockSizeID;
-       size_t blockSize = LZ4F_getBlockSize(bid);
-       unsigned nbBlocks = (unsigned)(srcSize / blockSize) + 1;
-       size_t lastBlockSize = preferencesPtr->autoFlush ? srcSize % blockSize : blockSize;
-       size_t blockInfo = 4;   /* default, without block CRC option */
-       size_t frameEnd = 4 + (frameInfoPtr->contentChecksumFlag*4);
-       size_t result = (blockInfo * nbBlocks) + (blockSize * (nbBlocks-1)) + lastBlockSize + frameEnd;
-
-       return result;
+    blockSizeID_t bid = (frameInfoPtr==NULL) ? LZ4F_BLOCKSIZEID_DEFAULT : frameInfoPtr->blockSizeID;
+    size_t blockSize = LZ4F_getBlockSize(bid);
+    unsigned nbBlocks = (unsigned)(srcSize / blockSize) + 1;
+    size_t lastBlockSize = preferencesPtr->autoFlush ? srcSize % blockSize : blockSize;
+    size_t blockInfo = 4;   /* default, without block CRC option */
+    size_t frameEnd = 4 + (frameInfoPtr->contentChecksumFlag*4);
+    size_t result = (blockInfo * nbBlocks) + (blockSize * (nbBlocks-1)) + lastBlockSize + frameEnd;
+
+    return result;
 }
 
 
@@ -456,66 +458,66 @@ typedef enum { notDone, fromTmpBuffer, fromSrcBuffer } LZ4F_lastBlockStatus;
  */
 size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* compressOptionsPtr)
 {
-       LZ4F_compressOptions_t cOptionsNull = { 0 };
-       LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
-       size_t blockSize = cctxPtr->maxBlockSize;
-       const BYTE* srcPtr = (const BYTE*)srcBuffer;
-       const BYTE* const srcEnd = srcPtr + srcSize;
-       BYTE* const dstStart = (BYTE*)dstBuffer;
-       BYTE* dstPtr = dstStart;
-       LZ4F_lastBlockStatus lastBlockCompressed = notDone;
-       compressFunc_t compress;
-
-
-       if (cctxPtr->cStage != 1) return (size_t)-ERROR_GENERIC;
-       if (dstMaxSize < LZ4F_compressBound(srcSize, &(cctxPtr->prefs))) return (size_t)-ERROR_dstMaxSize_tooSmall;
-       if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
-
-       /* select compression function */
-       compress = (cctxPtr->prefs.frameInfo.blockMode == blockLinked) ?
-            (int(*)(void*,const char*,char*,int,int))LZ4_compress_limitedOutput_continue :
-            LZ4_compress_limitedOutput_withState;
-
-       /* complete tmp buffer */
-       if (cctxPtr->tmpInSize > 0)   /* some data already within tmp buffer */
-       {
-               size_t sizeToCopy = blockSize - cctxPtr->tmpInSize;
-               if (sizeToCopy > srcSize)
-               {
-                       /* add src to tmpIn buffer */
-                       memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, srcSize);
-                       srcPtr = srcEnd;
-                       cctxPtr->tmpInSize += srcSize;
-                       /* still needs some CRC */
-               }
-               else
-               {
-                       /* complete tmpIn block and then compress it */
-                       lastBlockCompressed = fromTmpBuffer;
-                       memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, sizeToCopy);
-                       srcPtr += sizeToCopy;
-
-                       dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, blockSize, compress, &(cctxPtr->lz4ctx));
-
-                       if (cctxPtr->prefs.frameInfo.blockMode==blockLinked) cctxPtr->tmpIn += blockSize;
-                       cctxPtr->tmpInSize = 0;
-               }
-       }
-
-       while ((size_t)(srcEnd - srcPtr) >= blockSize)
-       {
-               /* compress full block */
+    LZ4F_compressOptions_t cOptionsNull = { 0 };
+    LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
+    size_t blockSize = cctxPtr->maxBlockSize;
+    const BYTE* srcPtr = (const BYTE*)srcBuffer;
+    const BYTE* const srcEnd = srcPtr + srcSize;
+    BYTE* const dstStart = (BYTE*)dstBuffer;
+    BYTE* dstPtr = dstStart;
+    LZ4F_lastBlockStatus lastBlockCompressed = notDone;
+    compressFunc_t compress;
+
+
+    if (cctxPtr->cStage != 1) return (size_t)-ERROR_GENERIC;
+    if (dstMaxSize < LZ4F_compressBound(srcSize, &(cctxPtr->prefs))) return (size_t)-ERROR_dstMaxSize_tooSmall;
+    if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
+
+    /* select compression function */
+    compress = (cctxPtr->prefs.frameInfo.blockMode == blockLinked) ?
+               (int(*)(void*,const char*,char*,int,int))LZ4_compress_limitedOutput_continue :
+               LZ4_compress_limitedOutput_withState;
+
+    /* complete tmp buffer */
+    if (cctxPtr->tmpInSize > 0)   /* some data already within tmp buffer */
+    {
+        size_t sizeToCopy = blockSize - cctxPtr->tmpInSize;
+        if (sizeToCopy > srcSize)
+        {
+            /* add src to tmpIn buffer */
+            memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, srcSize);
+            srcPtr = srcEnd;
+            cctxPtr->tmpInSize += srcSize;
+            /* still needs some CRC */
+        }
+        else
+        {
+            /* complete tmpIn block and then compress it */
+            lastBlockCompressed = fromTmpBuffer;
+            memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, sizeToCopy);
+            srcPtr += sizeToCopy;
+
+            dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, blockSize, compress, &(cctxPtr->lz4ctx));
+
+            if (cctxPtr->prefs.frameInfo.blockMode==blockLinked) cctxPtr->tmpIn += blockSize;
+            cctxPtr->tmpInSize = 0;
+        }
+    }
+
+    while ((size_t)(srcEnd - srcPtr) >= blockSize)
+    {
+        /* compress full block */
         lastBlockCompressed = fromSrcBuffer;
         dstPtr += LZ4F_compressBlock(dstPtr, srcPtr, blockSize, compress, &(cctxPtr->lz4ctx));
-               srcPtr += blockSize;
-       }
+        srcPtr += blockSize;
+    }
 
     if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd))
     {
         /* compress remaining input < blockSize */
         lastBlockCompressed = fromSrcBuffer;
         dstPtr += LZ4F_compressBlock(dstPtr, srcPtr, srcEnd - srcPtr, compress, &(cctxPtr->lz4ctx));
-               srcPtr  = srcEnd;
+        srcPtr  = srcEnd;
     }
 
     /* preserve dictionary if necessary */
@@ -542,7 +544,7 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d
     }
 
     /* some input data left, necessarily < blockSize */
-       if (srcPtr < srcEnd)
+    if (srcPtr < srcEnd)
     {
         /* fill tmp buffer */
         size_t sizeToCopy = srcEnd - srcPtr;
@@ -550,10 +552,10 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d
         cctxPtr->tmpInSize = sizeToCopy;
     }
 
-       if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled)
-               XXH32_update(&(cctxPtr->xxh), srcBuffer, (unsigned)srcSize);
+    if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled)
+        XXH32_update(&(cctxPtr->xxh), srcBuffer, (unsigned)srcSize);
 
-       return dstPtr - dstStart;
+    return dstPtr - dstStart;
 }
 
 
@@ -567,27 +569,28 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d
  */
 size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_compressOptions_t* compressOptionsPtr)
 {
-       LZ4F_compressOptions_t cOptionsNull = { 0 };
-       LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
-       BYTE* const dstStart = (BYTE*)dstBuffer;
-       BYTE* dstPtr = dstStart;
-       int (*compress)(void*, const char*, char*, int, int);
+    LZ4F_compressOptions_t cOptionsNull = { 0 };
+    LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
+    BYTE* const dstStart = (BYTE*)dstBuffer;
+    BYTE* dstPtr = dstStart;
+    int (*compress)(void*, const char*, char*, int, int);
 
 
-       if (cctxPtr->tmpInSize == 0) return 0;   /* nothing to flush */
-       if (cctxPtr->cStage != 1) return (size_t)-ERROR_GENERIC;
-       if (dstMaxSize < (cctxPtr->tmpInSize + 16)) return (size_t)-ERROR_dstMaxSize_tooSmall;
-       if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
+    if (cctxPtr->tmpInSize == 0) return 0;   /* nothing to flush */
+    if (cctxPtr->cStage != 1) return (size_t)-ERROR_GENERIC;
+    if (dstMaxSize < (cctxPtr->tmpInSize + 16)) return (size_t)-ERROR_dstMaxSize_tooSmall;
+    if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
+    (void)compressOptionsPtr;   /* not yet useful */
 
-       /* select compression function */
-       compress = (cctxPtr->prefs.frameInfo.blockMode == blockLinked) ?
-            (int(*)(void*,const char*,char*,int,int))LZ4_compress_limitedOutput_continue :
-            LZ4_compress_limitedOutput_withState;
+    /* select compression function */
+    compress = (cctxPtr->prefs.frameInfo.blockMode == blockLinked) ?
+               (int(*)(void*,const char*,char*,int,int))LZ4_compress_limitedOutput_continue :
+               LZ4_compress_limitedOutput_withState;
 
     /* compress tmp buffer */
     dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, cctxPtr->tmpInSize, compress, &(cctxPtr->lz4ctx));
     if (cctxPtr->prefs.frameInfo.blockMode==blockLinked) cctxPtr->tmpIn += cctxPtr->tmpInSize;
-       cctxPtr->tmpInSize = 0;
+    cctxPtr->tmpInSize = 0;
 
     /* keep tmpIn within limits */
     if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize))   /* necessarily blockLinked */
@@ -596,7 +599,7 @@ size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer,
         cctxPtr->tmpIn = cctxPtr->tmpBuff + 64 KB;
     }
 
-       return dstPtr - dstStart;
+    return dstPtr - dstStart;
 }
 
 
@@ -611,27 +614,28 @@ size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer,
  */
 size_t LZ4F_compressEnd(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_compressOptions_t* compressOptionsPtr)
 {
-       LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
-       BYTE* const dstStart = (BYTE*)dstBuffer;
-       BYTE* dstPtr = dstStart;
-       size_t errorCode;
+    LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
+    BYTE* const dstStart = (BYTE*)dstBuffer;
+    BYTE* dstPtr = dstStart;
+    size_t errorCode;
 
-       errorCode = LZ4F_flush(compressionContext, dstBuffer, dstMaxSize, compressOptionsPtr);
-       if (LZ4F_isError(errorCode)) return errorCode;
-       dstPtr += errorCode;
+    errorCode = LZ4F_flush(compressionContext, dstBuffer, dstMaxSize, compressOptionsPtr);
+    if (LZ4F_isError(errorCode)) return errorCode;
+    dstPtr += errorCode;
 
-       LZ4F_writeLE32(dstPtr, 0); dstPtr+=4;   /* endMark */
+    LZ4F_writeLE32(dstPtr, 0);
+    dstPtr+=4;   /* endMark */
 
-       if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled)
-       {
-               U32 xxh = XXH32_intermediateDigest(&(cctxPtr->xxh));
-               LZ4F_writeLE32(dstPtr, xxh);
-               dstPtr+=4;   /* content Checksum */
-       }
+    if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled)
+    {
+        U32 xxh = XXH32_intermediateDigest(&(cctxPtr->xxh));
+        LZ4F_writeLE32(dstPtr, xxh);
+        dstPtr+=4;   /* content Checksum */
+    }
 
-       cctxPtr->cStage = 0;   /* state is now re-usable (with identical preferences) */
+    cctxPtr->cStage = 0;   /* state is now re-usable (with identical preferences) */
 
-       return dstPtr - dstStart;
+    return dstPtr - dstStart;
 }
 
 
@@ -748,7 +752,8 @@ typedef enum { dstage_getHeader=0, dstage_storeHeader, dstage_decodeHeader,
                dstage_copyDirect,
                dstage_getCBlock, dstage_storeCBlock, dstage_decodeCBlock,
                dstage_decodeCBlock_intoDst, dstage_decodeCBlock_intoTmp, dstage_flushOut,
-               dstage_getSuffix, dstage_storeSuffix, dstage_checkSuffix } dStage_t;
+               dstage_getSuffix, dstage_storeSuffix, dstage_checkSuffix
+             } dStage_t;
 
 
 /* LZ4F_getFrameInfo()
@@ -785,7 +790,8 @@ LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t decompressionCont
 
 static int LZ4F_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize)
 {
-    (void)dictStart; (void)dictSize;
+    (void)dictStart;
+    (void)dictSize;
     return LZ4_decompress_safe (source, dest, compressedSize, maxDecompressedSize);
 }
 
@@ -903,7 +909,8 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext,
 
 
     if (decompressOptionsPtr==NULL) decompressOptionsPtr = &optionsNull;
-    *srcSizePtr = 0; *dstSizePtr = 0;
+    *srcSizePtr = 0;
+    *dstSizePtr = 0;
 
     /* expect to continue decoding src buffer where it left previously */
     if (dctxPtr->srcExpect != NULL)
@@ -920,314 +927,314 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext,
         {
 
         case dstage_getHeader:
+        {
+            if (srcEnd-srcPtr >= 7)
             {
-                if (srcEnd-srcPtr >= 7)
-                {
-                    selectedIn = srcPtr;
-                    srcPtr += 7;
-                    dctxPtr->dStage = dstage_decodeHeader;
-                    break;
-                }
-                dctxPtr->tmpInSize = 0;
-                dctxPtr->dStage = dstage_storeHeader;
+                selectedIn = srcPtr;
+                srcPtr += 7;
+                dctxPtr->dStage = dstage_decodeHeader;
                 break;
             }
+            dctxPtr->tmpInSize = 0;
+            dctxPtr->dStage = dstage_storeHeader;
+            break;
+        }
 
         case dstage_storeHeader:
+        {
+            size_t sizeToCopy = 7 - dctxPtr->tmpInSize;
+            if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy =  srcEnd - srcPtr;
+            memcpy(dctxPtr->header + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
+            dctxPtr->tmpInSize += sizeToCopy;
+            srcPtr += sizeToCopy;
+            if (dctxPtr->tmpInSize < 7)
             {
-                size_t sizeToCopy = 7 - dctxPtr->tmpInSize;
-                if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy =  srcEnd - srcPtr;
-                memcpy(dctxPtr->header + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
-                dctxPtr->tmpInSize += sizeToCopy;
-                srcPtr += sizeToCopy;
-                if (dctxPtr->tmpInSize < 7)
-                {
-                    nextSrcSizeHint = (7 - dctxPtr->tmpInSize) + 4;
-                    doAnotherStage = 0;   /* no enough src, wait to get some more */
-                    break;
-                }
-                selectedIn = dctxPtr->header;
-                dctxPtr->dStage = dstage_decodeHeader;
+                nextSrcSizeHint = (7 - dctxPtr->tmpInSize) + 4;
+                doAnotherStage = 0;   /* no enough src, wait to get some more */
                 break;
             }
+            selectedIn = dctxPtr->header;
+            dctxPtr->dStage = dstage_decodeHeader;
+            break;
+        }
 
         case dstage_decodeHeader:
-            {
-                LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, selectedIn, 7);
-                if (LZ4F_isError(errorCode)) return errorCode;
-                dctxPtr->dStage = dstage_getCBlockSize;
-                break;
-            }
+        {
+            LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, selectedIn, 7);
+            if (LZ4F_isError(errorCode)) return errorCode;
+            dctxPtr->dStage = dstage_getCBlockSize;
+            break;
+        }
 
         case dstage_getCBlockSize:
+        {
+            if ((srcEnd - srcPtr) >= 4)
             {
-                if ((srcEnd - srcPtr) >= 4)
-                {
-                    selectedIn = srcPtr;
-                    srcPtr += 4;
-                    dctxPtr->dStage = dstage_decodeCBlockSize;
-                    break;
-                }
-                /* not enough input to read cBlockSize field */
-                dctxPtr->tmpInSize = 0;
-                dctxPtr->dStage = dstage_storeCBlockSize;
+                selectedIn = srcPtr;
+                srcPtr += 4;
+                dctxPtr->dStage = dstage_decodeCBlockSize;
                 break;
             }
+            /* not enough input to read cBlockSize field */
+            dctxPtr->tmpInSize = 0;
+            dctxPtr->dStage = dstage_storeCBlockSize;
+            break;
+        }
 
         case dstage_storeCBlockSize:
+        {
+            size_t sizeToCopy = 4 - dctxPtr->tmpInSize;
+            if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
+            memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
+            srcPtr += sizeToCopy;
+            dctxPtr->tmpInSize += sizeToCopy;
+            if (dctxPtr->tmpInSize < 4) /* not enough input to get full cBlockSize; wait for more */
             {
-                size_t sizeToCopy = 4 - dctxPtr->tmpInSize;
-                if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
-                memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
-                srcPtr += sizeToCopy;
-                dctxPtr->tmpInSize += sizeToCopy;
-                if (dctxPtr->tmpInSize < 4) /* not enough input to get full cBlockSize; wait for more */
-                {
-                    nextSrcSizeHint = 4 - dctxPtr->tmpInSize;
-                    doAnotherStage=0;
-                    break;
-                }
-                selectedIn = dctxPtr->tmpIn;
-                dctxPtr->dStage = dstage_decodeCBlockSize;
+                nextSrcSizeHint = 4 - dctxPtr->tmpInSize;
+                doAnotherStage=0;
                 break;
             }
+            selectedIn = dctxPtr->tmpIn;
+            dctxPtr->dStage = dstage_decodeCBlockSize;
+            break;
+        }
 
         case dstage_decodeCBlockSize:
+        {
+            size_t nextCBlockSize = LZ4F_readLE32(selectedIn) & 0x7FFFFFFFU;
+            if (nextCBlockSize==0)   /* frameEnd signal, no more CBlock */
             {
-                size_t nextCBlockSize = LZ4F_readLE32(selectedIn) & 0x7FFFFFFFU;
-                if (nextCBlockSize==0)   /* frameEnd signal, no more CBlock */
-                {
-                    dctxPtr->dStage = dstage_getSuffix;
-                    break;
-                }
-                if (nextCBlockSize > dctxPtr->maxBlockSize) return (size_t)-ERROR_GENERIC;   /* invalid cBlockSize */
-                dctxPtr->tmpInTarget = nextCBlockSize;
-                if (LZ4F_readLE32(selectedIn) & LZ4F_BLOCKUNCOMPRESSED_FLAG)
-                {
-                    dctxPtr->dStage = dstage_copyDirect;
-                    break;
-                }
-                dctxPtr->dStage = dstage_getCBlock;
-                if (dstPtr==dstEnd)
-                {
-                    nextSrcSizeHint = nextCBlockSize + 4;
-                    doAnotherStage = 0;
-                }
+                dctxPtr->dStage = dstage_getSuffix;
+                break;
+            }
+            if (nextCBlockSize > dctxPtr->maxBlockSize) return (size_t)-ERROR_GENERIC;   /* invalid cBlockSize */
+            dctxPtr->tmpInTarget = nextCBlockSize;
+            if (LZ4F_readLE32(selectedIn) & LZ4F_BLOCKUNCOMPRESSED_FLAG)
+            {
+                dctxPtr->dStage = dstage_copyDirect;
                 break;
             }
+            dctxPtr->dStage = dstage_getCBlock;
+            if (dstPtr==dstEnd)
+            {
+                nextSrcSizeHint = nextCBlockSize + 4;
+                doAnotherStage = 0;
+            }
+            break;
+        }
 
         case dstage_copyDirect:   /* uncompressed block */
+        {
+            size_t sizeToCopy = dctxPtr->tmpInTarget;
+            if ((size_t)(srcEnd-srcPtr) < sizeToCopy) sizeToCopy = srcEnd - srcPtr;  /* not enough input to read full block */
+            if ((size_t)(dstEnd-dstPtr) < sizeToCopy) sizeToCopy = dstEnd - dstPtr;
+            memcpy(dstPtr, srcPtr, sizeToCopy);
+            if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), srcPtr, (U32)sizeToCopy);
+
+            /* dictionary management */
+            if (dctxPtr->frameInfo.blockMode==blockLinked)
+                LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 0);
+
+            srcPtr += sizeToCopy;
+            dstPtr += sizeToCopy;
+            if (sizeToCopy == dctxPtr->tmpInTarget)   /* all copied */
             {
-                size_t sizeToCopy = dctxPtr->tmpInTarget;
-                if ((size_t)(srcEnd-srcPtr) < sizeToCopy) sizeToCopy = srcEnd - srcPtr;  /* not enough input to read full block */
-                if ((size_t)(dstEnd-dstPtr) < sizeToCopy) sizeToCopy = dstEnd - dstPtr;
-                memcpy(dstPtr, srcPtr, sizeToCopy);
-                if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), srcPtr, (U32)sizeToCopy);
-
-                /* dictionary management */
-                if (dctxPtr->frameInfo.blockMode==blockLinked)
-                    LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 0);
-
-                srcPtr += sizeToCopy;
-                dstPtr += sizeToCopy;
-                if (sizeToCopy == dctxPtr->tmpInTarget)   /* all copied */
-                {
-                    dctxPtr->dStage = dstage_getCBlockSize;
-                    break;
-                }
-                dctxPtr->tmpInTarget -= sizeToCopy;   /* still need to copy more */
-                nextSrcSizeHint = dctxPtr->tmpInTarget + 4;
-                doAnotherStage = 0;
+                dctxPtr->dStage = dstage_getCBlockSize;
                 break;
             }
+            dctxPtr->tmpInTarget -= sizeToCopy;   /* still need to copy more */
+            nextSrcSizeHint = dctxPtr->tmpInTarget + 4;
+            doAnotherStage = 0;
+            break;
+        }
 
         case dstage_getCBlock:   /* entry from dstage_decodeCBlockSize */
+        {
+            if ((size_t)(srcEnd-srcPtr) < dctxPtr->tmpInTarget)
             {
-                if ((size_t)(srcEnd-srcPtr) < dctxPtr->tmpInTarget)
-                {
-                    dctxPtr->tmpInSize = 0;
-                    dctxPtr->dStage = dstage_storeCBlock;
-                    break;
-                }
-                selectedIn = srcPtr;
-                srcPtr += dctxPtr->tmpInTarget;
-                dctxPtr->dStage = dstage_decodeCBlock;
+                dctxPtr->tmpInSize = 0;
+                dctxPtr->dStage = dstage_storeCBlock;
                 break;
             }
+            selectedIn = srcPtr;
+            srcPtr += dctxPtr->tmpInTarget;
+            dctxPtr->dStage = dstage_decodeCBlock;
+            break;
+        }
 
         case dstage_storeCBlock:
+        {
+            size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
+            if (sizeToCopy > (size_t)(srcEnd-srcPtr)) sizeToCopy = srcEnd-srcPtr;
+            memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
+            dctxPtr->tmpInSize += sizeToCopy;
+            srcPtr += sizeToCopy;
+            if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget)  /* need more input */
             {
-                size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize;
-                if (sizeToCopy > (size_t)(srcEnd-srcPtr)) sizeToCopy = srcEnd-srcPtr;
-                memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
-                dctxPtr->tmpInSize += sizeToCopy;
-                srcPtr += sizeToCopy;
-                if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget)  /* need more input */
-                {
-                    nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + 4;
-                    doAnotherStage=0;
-                    break;
-                }
-                selectedIn = dctxPtr->tmpIn;
-                dctxPtr->dStage = dstage_decodeCBlock;
+                nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + 4;
+                doAnotherStage=0;
                 break;
             }
+            selectedIn = dctxPtr->tmpIn;
+            dctxPtr->dStage = dstage_decodeCBlock;
+            break;
+        }
 
         case dstage_decodeCBlock:
-            {
-                if ((size_t)(dstEnd-dstPtr) < dctxPtr->maxBlockSize)   /* not enough place into dst : decode into tmpOut */
-                    dctxPtr->dStage = dstage_decodeCBlock_intoTmp;
-                else
-                    dctxPtr->dStage = dstage_decodeCBlock_intoDst;
-                break;
-            }
+        {
+            if ((size_t)(dstEnd-dstPtr) < dctxPtr->maxBlockSize)   /* not enough place into dst : decode into tmpOut */
+                dctxPtr->dStage = dstage_decodeCBlock_intoTmp;
+            else
+                dctxPtr->dStage = dstage_decodeCBlock_intoDst;
+            break;
+        }
 
         case dstage_decodeCBlock_intoDst:
-            {
-                int (*decoder)(const char*, char*, int, int, const char*, int);
-                int decodedSize;
+        {
+            int (*decoder)(const char*, char*, int, int, const char*, int);
+            int decodedSize;
 
-                if (dctxPtr->frameInfo.blockMode == blockLinked)
-                    decoder = LZ4_decompress_safe_usingDict;
-                else
-                    decoder = LZ4F_decompress_safe;
+            if (dctxPtr->frameInfo.blockMode == blockLinked)
+                decoder = LZ4_decompress_safe_usingDict;
+            else
+                decoder = LZ4F_decompress_safe;
 
-                decodedSize = decoder((const char*)selectedIn, (char*)dstPtr, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
-                if (decodedSize < 0) return (size_t)-ERROR_GENERIC;   /* decompression failed */
-                if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dstPtr, decodedSize);
+            decodedSize = decoder((const char*)selectedIn, (char*)dstPtr, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
+            if (decodedSize < 0) return (size_t)-ERROR_GENERIC;   /* decompression failed */
+            if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dstPtr, decodedSize);
 
-                /* dictionary management */
-                if (dctxPtr->frameInfo.blockMode==blockLinked)
-                    LZ4F_updateDict(dctxPtr, dstPtr, decodedSize, dstStart, 0);
+            /* dictionary management */
+            if (dctxPtr->frameInfo.blockMode==blockLinked)
+                LZ4F_updateDict(dctxPtr, dstPtr, decodedSize, dstStart, 0);
 
-                dstPtr += decodedSize;
-                dctxPtr->dStage = dstage_getCBlockSize;
-                break;
-            }
+            dstPtr += decodedSize;
+            dctxPtr->dStage = dstage_getCBlockSize;
+            break;
+        }
 
         case dstage_decodeCBlock_intoTmp:
-            {
-                /* not enough place into dst : decode into tmpOut */
-                int (*decoder)(const char*, char*, int, int, const char*, int);
-                int decodedSize;
+        {
+            /* not enough place into dst : decode into tmpOut */
+            int (*decoder)(const char*, char*, int, int, const char*, int);
+            int decodedSize;
 
-                if (dctxPtr->frameInfo.blockMode == blockLinked)
-                    decoder = LZ4_decompress_safe_usingDict;
-                else
-                    decoder = LZ4F_decompress_safe;
+            if (dctxPtr->frameInfo.blockMode == blockLinked)
+                decoder = LZ4_decompress_safe_usingDict;
+            else
+                decoder = LZ4F_decompress_safe;
 
-                /* ensure enough place for tmpOut */
-                if (dctxPtr->frameInfo.blockMode == blockLinked)
+            /* ensure enough place for tmpOut */
+            if (dctxPtr->frameInfo.blockMode == blockLinked)
+            {
+                if (dctxPtr->dict == dctxPtr->tmpOutBuffer)
                 {
-                    if (dctxPtr->dict == dctxPtr->tmpOutBuffer)
-                    {
-                        if (dctxPtr->dictSize > 128 KB)
-                        {
-                            memcpy(dctxPtr->dict, dctxPtr->dict + dctxPtr->dictSize - 64 KB, 64 KB);
-                            dctxPtr->dictSize = 64 KB;
-                        }
-                        dctxPtr->tmpOut = dctxPtr->dict + dctxPtr->dictSize;
-                    }
-                    else   /* dict not within tmp */
+                    if (dctxPtr->dictSize > 128 KB)
                     {
-                        size_t reservedDictSpace = dctxPtr->dictSize;
-                        if (reservedDictSpace > 64 KB) reservedDictSpace = 64 KB;
-                        dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + reservedDictSpace;
+                        memcpy(dctxPtr->dict, dctxPtr->dict + dctxPtr->dictSize - 64 KB, 64 KB);
+                        dctxPtr->dictSize = 64 KB;
                     }
+                    dctxPtr->tmpOut = dctxPtr->dict + dctxPtr->dictSize;
+                }
+                else   /* dict not within tmp */
+                {
+                    size_t reservedDictSpace = dctxPtr->dictSize;
+                    if (reservedDictSpace > 64 KB) reservedDictSpace = 64 KB;
+                    dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + reservedDictSpace;
                 }
-
-                /* Decode */
-                decodedSize = decoder((const char*)selectedIn, (char*)dctxPtr->tmpOut, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
-                if (decodedSize < 0) return (size_t)-ERROR_decompressionFailed;   /* decompression failed */
-                if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dctxPtr->tmpOut, decodedSize);
-                dctxPtr->tmpOutSize = decodedSize;
-                dctxPtr->tmpOutStart = 0;
-                dctxPtr->dStage = dstage_flushOut;
-                break;
             }
 
+            /* Decode */
+            decodedSize = decoder((const char*)selectedIn, (char*)dctxPtr->tmpOut, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize);
+            if (decodedSize < 0) return (size_t)-ERROR_decompressionFailed;   /* decompression failed */
+            if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dctxPtr->tmpOut, decodedSize);
+            dctxPtr->tmpOutSize = decodedSize;
+            dctxPtr->tmpOutStart = 0;
+            dctxPtr->dStage = dstage_flushOut;
+            break;
+        }
+
         case dstage_flushOut:  /* flush decoded data from tmpOut to dstBuffer */
-            {
-                size_t sizeToCopy = dctxPtr->tmpOutSize - dctxPtr->tmpOutStart;
-                if (sizeToCopy > (size_t)(dstEnd-dstPtr)) sizeToCopy = dstEnd-dstPtr;
-                memcpy(dstPtr, dctxPtr->tmpOut + dctxPtr->tmpOutStart, sizeToCopy);
+        {
+            size_t sizeToCopy = dctxPtr->tmpOutSize - dctxPtr->tmpOutStart;
+            if (sizeToCopy > (size_t)(dstEnd-dstPtr)) sizeToCopy = dstEnd-dstPtr;
+            memcpy(dstPtr, dctxPtr->tmpOut + dctxPtr->tmpOutStart, sizeToCopy);
 
-                /* dictionary management */
-                if (dctxPtr->frameInfo.blockMode==blockLinked)
-                    LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 1);
+            /* dictionary management */
+            if (dctxPtr->frameInfo.blockMode==blockLinked)
+                LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 1);
 
-                dctxPtr->tmpOutStart += sizeToCopy;
-                dstPtr += sizeToCopy;
+            dctxPtr->tmpOutStart += sizeToCopy;
+            dstPtr += sizeToCopy;
 
-                /* end of flush ? */
-                if (dctxPtr->tmpOutStart == dctxPtr->tmpOutSize)
-                {
-                    dctxPtr->dStage = dstage_getCBlockSize;
-                    break;
-                }
-                nextSrcSizeHint = 4;
-                doAnotherStage = 0;   /* still some data to flush */
+            /* end of flush ? */
+            if (dctxPtr->tmpOutStart == dctxPtr->tmpOutSize)
+            {
+                dctxPtr->dStage = dstage_getCBlockSize;
                 break;
             }
+            nextSrcSizeHint = 4;
+            doAnotherStage = 0;   /* still some data to flush */
+            break;
+        }
 
-       case dstage_getSuffix:
+        case dstage_getSuffix:
+        {
+            size_t suffixSize = dctxPtr->frameInfo.contentChecksumFlag * 4;
+            if (suffixSize == 0)   /* frame completed */
             {
-                size_t suffixSize = dctxPtr->frameInfo.contentChecksumFlag * 4;
-                if (suffixSize == 0)   /* frame completed */
-                {
-                    nextSrcSizeHint = 0;
-                    dctxPtr->dStage = dstage_getHeader;
-                    doAnotherStage = 0;
-                    break;
-                }
-                if ((srcEnd - srcPtr) >= 4)   /* CRC present */
-                {
-                    selectedIn = srcPtr;
-                    srcPtr += 4;
-                    dctxPtr->dStage = dstage_checkSuffix;
-                    break;
-                }
-                dctxPtr->tmpInSize = 0;
-                dctxPtr->dStage = dstage_storeSuffix;
+                nextSrcSizeHint = 0;
+                dctxPtr->dStage = dstage_getHeader;
+                doAnotherStage = 0;
                 break;
             }
-
-        case dstage_storeSuffix:
+            if ((srcEnd - srcPtr) >= 4)   /* CRC present */
             {
-                size_t sizeToCopy = 4 - dctxPtr->tmpInSize;
-                if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
-                memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
-                srcPtr += sizeToCopy;
-                dctxPtr->tmpInSize += sizeToCopy;
-                if (dctxPtr->tmpInSize < 4)  /* not enough input to read complete suffix */
-                {
-                    nextSrcSizeHint = 4 - dctxPtr->tmpInSize;
-                    doAnotherStage=0;
-                    break;
-                }
-                selectedIn = dctxPtr->tmpIn;
+                selectedIn = srcPtr;
+                srcPtr += 4;
                 dctxPtr->dStage = dstage_checkSuffix;
                 break;
             }
+            dctxPtr->tmpInSize = 0;
+            dctxPtr->dStage = dstage_storeSuffix;
+            break;
+        }
 
-        case dstage_checkSuffix:
+        case dstage_storeSuffix:
+        {
+            size_t sizeToCopy = 4 - dctxPtr->tmpInSize;
+            if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
+            memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy);
+            srcPtr += sizeToCopy;
+            dctxPtr->tmpInSize += sizeToCopy;
+            if (dctxPtr->tmpInSize < 4)  /* not enough input to read complete suffix */
             {
-                U32 readCRC = LZ4F_readLE32(selectedIn);
-                U32 resultCRC = XXH32_intermediateDigest(&(dctxPtr->xxh));
-                if (readCRC != resultCRC) return (size_t)-ERROR_checksum_invalid;
-                nextSrcSizeHint = 0;
-                dctxPtr->dStage = dstage_getHeader;
-                doAnotherStage = 0;
+                nextSrcSizeHint = 4 - dctxPtr->tmpInSize;
+                doAnotherStage=0;
                 break;
             }
+            selectedIn = dctxPtr->tmpIn;
+            dctxPtr->dStage = dstage_checkSuffix;
+            break;
+        }
+
+        case dstage_checkSuffix:
+        {
+            U32 readCRC = LZ4F_readLE32(selectedIn);
+            U32 resultCRC = XXH32_intermediateDigest(&(dctxPtr->xxh));
+            if (readCRC != resultCRC) return (size_t)-ERROR_checksum_invalid;
+            nextSrcSizeHint = 0;
+            dctxPtr->dStage = dstage_getHeader;
+            doAnotherStage = 0;
+            break;
+        }
         }
     }
 
     /* preserve dictionary within tmp if necessary */
     if ( (dctxPtr->frameInfo.blockMode==blockLinked)
-       &&(dctxPtr->dict != dctxPtr->tmpOutBuffer)
-       &&(!decompressOptionsPtr->stableDst)
-       &&((unsigned)(dctxPtr->dStage-1) < (unsigned)(dstage_getSuffix-1))
+            &&(dctxPtr->dict != dctxPtr->tmpOutBuffer)
+            &&(!decompressOptionsPtr->stableDst)
+            &&((unsigned)(dctxPtr->dStage-1) < (unsigned)(dstage_getSuffix-1))
        )
     {
         if (dctxPtr->dStage == dstage_flushOut)
index 19e8e82..3d19ef4 100644 (file)
 **************************************/
 #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)   /* C99 */
 # include <stdint.h>
-  typedef  uint8_t BYTE;
-  typedef uint16_t U16;
-  typedef uint32_t U32;
-  typedef  int32_t S32;
-  typedef uint64_t U64;
+typedef  uint8_t BYTE;
+typedef uint16_t U16;
+typedef uint32_t U32;
+typedef  int32_t S32;
+typedef uint64_t U64;
 #else
-  typedef unsigned char       BYTE;
-  typedef unsigned short      U16;
-  typedef unsigned int        U32;
-  typedef   signed int        S32;
-  typedef unsigned long long  U64;
+typedef unsigned char       BYTE;
+typedef unsigned short      U16;
+typedef unsigned int        U32;
+typedef   signed int        S32;
+typedef unsigned long long  U64;
 #endif
 
 
@@ -113,21 +113,21 @@ static U32 pause = 0;
 *********************************************************/
 static U32 FUZ_GetMilliStart(void)
 {
-   struct timeb tb;
-   U32 nCount;
-   ftime( &tb );
-   nCount = (U32) (((tb.time & 0xFFFFF) * 1000) +  tb.millitm);
-   return nCount;
+    struct timeb tb;
+    U32 nCount;
+    ftime( &tb );
+    nCount = (U32) (((tb.time & 0xFFFFF) * 1000) +  tb.millitm);
+    return nCount;
 }
 
 
 static U32 FUZ_GetMilliSpan(U32 nTimeStart)
 {
-   U32 nCurrent = FUZ_GetMilliStart();
-   U32 nSpan = nCurrent - nTimeStart;
-   if (nTimeStart > nCurrent)
-      nSpan += 0x100000 * 1000;
-   return nSpan;
+    U32 nCurrent = FUZ_GetMilliStart();
+    U32 nSpan = nCurrent - nTimeStart;
+    if (nTimeStart > nCurrent)
+        nSpan += 0x100000 * 1000;
+    return nSpan;
 }
 
 
@@ -187,39 +187,43 @@ static unsigned FUZ_highbit(U32 v32)
 {
     unsigned nbBits = 0;
     if (v32==0) return 0;
-    while (v32) { v32 >>= 1; nbBits ++; }
+    while (v32)
+    {
+        v32 >>= 1;
+        nbBits ++;
+    }
     return nbBits;
 }
 
 
 int basicTests(U32 seed, double compressibility)
 {
-       int testResult = 0;
-       void* CNBuffer;
-       void* compressedBuffer;
-       void* decodedBuffer;
-       U32 randState = seed;
-       size_t cSize, testSize;
-       LZ4F_preferences_t prefs = { 0 };
-       LZ4F_decompressionContext_t dCtx;
-       U64 crcOrig;
-
-       // Create compressible test buffer
-       CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
-       compressedBuffer = malloc(LZ4F_compressFrameBound(COMPRESSIBLE_NOISE_LENGTH, NULL));
-       decodedBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
-       FUZ_fillCompressibleNoiseBuffer(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, compressibility, &randState);
-       crcOrig = XXH64(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, 1);
-
-       // Trivial tests : one-step frame
-       testSize = COMPRESSIBLE_NOISE_LENGTH;
-       DISPLAYLEVEL(3, "Using NULL preferences : \n");
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, NULL), CNBuffer, testSize, NULL);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "Decompression test : \n");
-       {
+    int testResult = 0;
+    void* CNBuffer;
+    void* compressedBuffer;
+    void* decodedBuffer;
+    U32 randState = seed;
+    size_t cSize, testSize;
+    LZ4F_preferences_t prefs = { 0 };
+    LZ4F_decompressionContext_t dCtx;
+    U64 crcOrig;
+
+    // Create compressible test buffer
+    CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
+    compressedBuffer = malloc(LZ4F_compressFrameBound(COMPRESSIBLE_NOISE_LENGTH, NULL));
+    decodedBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
+    FUZ_fillCompressibleNoiseBuffer(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, compressibility, &randState);
+    crcOrig = XXH64(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, 1);
+
+    // Trivial tests : one-step frame
+    testSize = COMPRESSIBLE_NOISE_LENGTH;
+    DISPLAYLEVEL(3, "Using NULL preferences : \n");
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, NULL), CNBuffer, testSize, NULL);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "Decompression test : \n");
+    {
         size_t decodedBufferSize = COMPRESSIBLE_NOISE_LENGTH;
         size_t compressedBufferSize = cSize;
         BYTE* op = (BYTE*)decodedBuffer;
@@ -254,30 +258,30 @@ int basicTests(U32 seed, double compressibility)
 
         errorCode = LZ4F_freeDecompressionContext(dCtx);
         if (LZ4F_isError(errorCode)) goto _output_error;
-       }
-
-       DISPLAYLEVEL(3, "Using 64 KB block : \n");
-       prefs.frameInfo.blockSizeID = max64KB;
-       prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "without checksum : \n");
-       prefs.frameInfo.contentChecksumFlag = noContentChecksum;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "Using 256 KB block : \n");
-       prefs.frameInfo.blockSizeID = max256KB;
-       prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "Decompression test : \n");
-       {
+    }
+
+    DISPLAYLEVEL(3, "Using 64 KB block : \n");
+    prefs.frameInfo.blockSizeID = max64KB;
+    prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "without checksum : \n");
+    prefs.frameInfo.contentChecksumFlag = noContentChecksum;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "Using 256 KB block : \n");
+    prefs.frameInfo.blockSizeID = max256KB;
+    prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "Decompression test : \n");
+    {
         size_t decodedBufferSize = COMPRESSIBLE_NOISE_LENGTH;
         unsigned maxBits = FUZ_highbit((U32)decodedBufferSize);
         BYTE* op = (BYTE*)decodedBuffer;
@@ -308,51 +312,51 @@ int basicTests(U32 seed, double compressibility)
 
         errorCode = LZ4F_freeDecompressionContext(dCtx);
         if (LZ4F_isError(errorCode)) goto _output_error;
-       }
-
-       DISPLAYLEVEL(3, "without checksum : \n");
-       prefs.frameInfo.contentChecksumFlag = noContentChecksum;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "Using 1 MB block : \n");
-       prefs.frameInfo.blockSizeID = max1MB;
-       prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "without checksum : \n");
-       prefs.frameInfo.contentChecksumFlag = noContentChecksum;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "Using 4 MB block : \n");
-       prefs.frameInfo.blockSizeID = max4MB;
-       prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAYLEVEL(3, "without checksum : \n");
-       prefs.frameInfo.contentChecksumFlag = noContentChecksum;
-       cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
-       if (LZ4F_isError(cSize)) goto _output_error;
-       DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
-
-       DISPLAY("Basic tests completed \n");
+    }
+
+    DISPLAYLEVEL(3, "without checksum : \n");
+    prefs.frameInfo.contentChecksumFlag = noContentChecksum;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "Using 1 MB block : \n");
+    prefs.frameInfo.blockSizeID = max1MB;
+    prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "without checksum : \n");
+    prefs.frameInfo.contentChecksumFlag = noContentChecksum;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "Using 4 MB block : \n");
+    prefs.frameInfo.blockSizeID = max4MB;
+    prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAYLEVEL(3, "without checksum : \n");
+    prefs.frameInfo.contentChecksumFlag = noContentChecksum;
+    cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs);
+    if (LZ4F_isError(cSize)) goto _output_error;
+    DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize);
+
+    DISPLAY("Basic tests completed \n");
 _end:
-       free(CNBuffer);
-       free(compressedBuffer);
-       free(decodedBuffer);
-       return testResult;
+    free(CNBuffer);
+    free(compressedBuffer);
+    free(decodedBuffer);
+    return testResult;
 
 _output_error:
-       testResult = 1;
-       DISPLAY("Error detected ! \n");
-       goto _end;
+    testResult = 1;
+    DISPLAY("Error detected ! \n");
+    goto _end;
 }
 
 
@@ -361,44 +365,48 @@ static void locateBuffDiff(const void* buff1, const void* buff2, size_t size, un
     int p=0;
     BYTE* b1=(BYTE*)buff1;
     BYTE* b2=(BYTE*)buff2;
-    if (nonContiguous) { DISPLAY("Non-contiguous output test (%i bytes)\n", (int)size); return; }
+    if (nonContiguous)
+    {
+        DISPLAY("Non-contiguous output test (%i bytes)\n", (int)size);
+        return;
+    }
     while (b1[p]==b2[p]) p++;
     DISPLAY("Error at pos %i/%i : %02X != %02X \n", p, (int)size, b1[p], b2[p]);
- }
+}
 
 
 static const U32 srcDataLength = 9 MB;  /* needs to be > 2x4MB to test large blocks */
 
 int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressibility)
 {
-       unsigned testResult = 0;
-       unsigned testNb = 0;
-       void* srcBuffer = NULL;
-       void* compressedBuffer = NULL;
-       void* decodedBuffer = NULL;
-       U32 coreRand = seed;
-       LZ4F_decompressionContext_t dCtx = NULL;
-       LZ4F_compressionContext_t cCtx = NULL;
+    unsigned testResult = 0;
+    unsigned testNb = 0;
+    void* srcBuffer = NULL;
+    void* compressedBuffer = NULL;
+    void* decodedBuffer = NULL;
+    U32 coreRand = seed;
+    LZ4F_decompressionContext_t dCtx = NULL;
+    LZ4F_compressionContext_t cCtx = NULL;
     size_t result;
     XXH64_stateSpace_t xxh64;
 #   define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
-                            DISPLAY(" (seed %u, test nb %i)  \n", seed, testNb); goto _output_error; }
+                            DISPLAY(" (seed %u, test nb %u)  \n", seed, testNb); goto _output_error; }
 
-       // Create buffers
-       result = LZ4F_createDecompressionContext(&dCtx, LZ4F_VERSION);
+    // Create buffers
+    result = LZ4F_createDecompressionContext(&dCtx, LZ4F_VERSION);
     CHECK(LZ4F_isError(result), "Allocation failed (error %i)", (int)result);
-       result = LZ4F_createCompressionContext(&cCtx, LZ4F_VERSION);
+    result = LZ4F_createCompressionContext(&cCtx, LZ4F_VERSION);
     CHECK(LZ4F_isError(result), "Allocation failed (error %i)", (int)result);
-       srcBuffer = malloc(srcDataLength);
+    srcBuffer = malloc(srcDataLength);
     CHECK(srcBuffer==NULL, "srcBuffer Allocation failed");
-       compressedBuffer = malloc(LZ4F_compressFrameBound(srcDataLength, NULL));
+    compressedBuffer = malloc(LZ4F_compressFrameBound(srcDataLength, NULL));
     CHECK(compressedBuffer==NULL, "compressedBuffer Allocation failed");
-       decodedBuffer = malloc(srcDataLength);
+    decodedBuffer = malloc(srcDataLength);
     CHECK(decodedBuffer==NULL, "decodedBuffer Allocation failed");
-       FUZ_fillCompressibleNoiseBuffer(srcBuffer, srcDataLength, compressibility, &coreRand);
+    FUZ_fillCompressibleNoiseBuffer(srcBuffer, srcDataLength, compressibility, &coreRand);
 
     // jump to requested testNb
-       for (testNb =0; testNb < startTest; testNb++) (void)FUZ_rand(&coreRand);   // sync randomizer
+    for (testNb =0; testNb < startTest; testNb++) (void)FUZ_rand(&coreRand);   // sync randomizer
 
     // main fuzzer loop
     for ( ; testNb < nbTests; testNb++)
@@ -423,7 +431,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
         prefs.frameInfo.contentChecksumFlag = CCflag;
         prefs.autoFlush = autoflush;
 
-        DISPLAYUPDATE(2, "\r%5i   ", testNb);
+        DISPLAYUPDATE(2, "\r%5u   ", testNb);
         crcOrig = XXH64((BYTE*)srcBuffer+srcStart, (U32)srcSize, 1);
 
         if ((FUZ_rand(&randState)&0xF) == 2)
@@ -450,7 +458,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
                 size_t oSize = oend-op;
                 unsigned forceFlush = ((FUZ_rand(&randState) & 3) == 1);
                 if (iSize > (size_t)(iend-ip)) iSize = iend-ip;
-                cOptions.stableSrc = ((FUZ_rand(&randState) && 3) == 1);
+                cOptions.stableSrc = ((FUZ_rand(&randState) & 3) == 1);
 
                 result = LZ4F_compressUpdate(cCtx, op, oSize, ip, iSize, &cOptions);
                 CHECK(LZ4F_isError(result), "Compression failed (error %i)", (int)result);
@@ -508,25 +516,25 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
         }
     }
 
-       DISPLAYLEVEL(2, "\rAll tests completed   \n");
+    DISPLAYLEVEL(2, "\rAll tests completed   \n");
 
 _end:
     LZ4F_freeDecompressionContext(dCtx);
     LZ4F_freeCompressionContext(cCtx);
-       free(srcBuffer);
-       free(compressedBuffer);
-       free(decodedBuffer);
+    free(srcBuffer);
+    free(compressedBuffer);
+    free(decodedBuffer);
 
-       if (pause)
+    if (pause)
     {
         DISPLAY("press enter to finish \n");
         getchar();
     }
-       return testResult;
+    return testResult;
 
 _output_error:
-       testResult = 1;
-       goto _end;
+    testResult = 1;
+    goto _end;
 }
 
 
@@ -536,7 +544,7 @@ int FUZ_usage(void)
     DISPLAY( "      %s [args]\n", programName);
     DISPLAY( "\n");
     DISPLAY( "Arguments :\n");
-    DISPLAY( " -i#    : Nb of tests (default:%i) \n", nbTestsDefault);
+    DISPLAY( " -i#    : Nb of tests (default:%u) \n", nbTestsDefault);
     DISPLAY( " -s#    : Select seed (default:prompt user)\n");
     DISPLAY( " -t#    : Select starting test number (default:0)\n");
     DISPLAY( " -p#    : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT);
@@ -567,7 +575,13 @@ int main(int argc, char** argv)
         // Decode command (note : aggregated commands are allowed)
         if (argument[0]=='-')
         {
-            if (!strcmp(argument, "--no-prompt")) { no_prompt=1; seedset=1; displayLevel=1; continue; }
+            if (!strcmp(argument, "--no-prompt"))
+            {
+                no_prompt=1;
+                seedset=1;
+                displayLevel=1;
+                continue;
+            }
             argument++;
 
             while (*argument!=0)
@@ -596,7 +610,8 @@ int main(int argc, char** argv)
                     break;
                 case 's':
                     argument++;
-                    seed=0; seedset=1;
+                    seed=0;
+                    seedset=1;
                     while ((*argument>='0') && (*argument<='9'))
                     {
                         seed *= 10;
@@ -630,7 +645,8 @@ int main(int argc, char** argv)
                     argument++;
                     pause = 1;
                     break;
-                default: ;
+                default:
+                    ;
                     return FUZ_usage();
                 }
             }
index 70f0760..2d612e7 100644 (file)
 #  pragma warning(disable : 4127)      // disable: C4127: conditional expression is constant
 #endif
 
+#ifdef __clang__
+#  pragma clang diagnostic ignored "-Wunused-const-variable"   // const variable one is really used !
+#endif
+
 #define _FILE_OFFSET_BITS 64   // Large file support on 32-bits unix
 #define _POSIX_SOURCE 1        // for fileno() within <stdio.h> on unix
 
@@ -91,7 +95,7 @@
 
 #if defined(_MSC_VER)    // Visual Studio
 #  define swap32 _byteswap_ulong
-#elif GCC_VERSION >= 403
+#elif (GCC_VERSION >= 403) || defined(__clang__)
 #  define swap32 __builtin_bswap32
 #else
   static inline unsigned int swap32(unsigned int x)