]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
various minor style fixes
authorYann Collet <cyan@fb.com>
Wed, 3 Mar 2021 00:03:18 +0000 (16:03 -0800)
committerYann Collet <cyan@fb.com>
Wed, 3 Mar 2021 00:03:18 +0000 (16:03 -0800)
contrib/seekable_format/tests/seekable_tests.c
contrib/seekable_format/zstdseek_compress.c
contrib/seekable_format/zstdseek_decompress.c

index e9911c0846580b45d24356782d3aba524bb95b06..658b356dfacaa2a539d43109899388b69cefbb91 100644 (file)
@@ -1,6 +1,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <assert.h>
 
 #include "zstd_seekable.h"
 
@@ -35,20 +36,21 @@ int main(int argc, const char** argv)
         const size_t uncompressed_size = 32;
         uint8_t uncompressed_data[32];
 
-        ZSTD_seekable* stream = ZSTD_seekable_create();
-        size_t status = ZSTD_seekable_initBuff(stream, compressed_data, compressed_size);
-        if (ZSTD_isError(status)) {
-            ZSTD_seekable_free(stream);
-            goto _test_error;
-        }
+        ZSTD_seekable* const stream = ZSTD_seekable_create();
+        assert(stream != NULL);
+        {   size_t const status = ZSTD_seekable_initBuff(stream, compressed_data, compressed_size);
+            if (ZSTD_isError(status)) {
+                ZSTD_seekable_free(stream);
+                goto _test_error;
+        }   }
 
-        const size_t offset = 2;
         /* Should return an error, but not hang */
-        status = ZSTD_seekable_decompress(stream, uncompressed_data, uncompressed_size, offset);
-        if (!ZSTD_isError(status)) {
-            ZSTD_seekable_free(stream);
-            goto _test_error;
-        }
+        {   const size_t offset = 2;
+            size_t const status = ZSTD_seekable_decompress(stream, uncompressed_data, uncompressed_size, offset);
+            if (!ZSTD_isError(status)) {
+                ZSTD_seekable_free(stream);
+                goto _test_error;
+        }   }
 
         ZSTD_seekable_free(stream);
     }
index 3db29188757808bd69eacc7829b64e52a2cc285b..f153aee73e085c8b8975fd8abc465c3305c075b0 100644 (file)
@@ -19,6 +19,7 @@
 #include "zstd.h"
 #include "zstd_errors.h"
 #include "mem.h"
+
 #include "zstd_seekable.h"
 
 #define CHECK_Z(f) { size_t const ret = (f); if (ret != 0) return ret; }
@@ -75,7 +76,7 @@ size_t ZSTD_seekable_frameLog_allocVec(ZSTD_frameLog* fl)
     return 0;
 }
 
-size_t ZSTD_seekable_frameLog_freeVec(ZSTD_frameLog* fl)
+static size_t ZSTD_seekable_frameLog_freeVec(ZSTD_frameLog* fl)
 {
     if (fl != NULL) free(fl->entries);
     return 0;
@@ -83,7 +84,7 @@ size_t ZSTD_seekable_frameLog_freeVec(ZSTD_frameLog* fl)
 
 ZSTD_frameLog* ZSTD_seekable_createFrameLog(int checksumFlag)
 {
-    ZSTD_frameLog* fl = malloc(sizeof(ZSTD_frameLog));
+    ZSTD_frameLog* const fl = malloc(sizeof(ZSTD_frameLog));
     if (fl == NULL) return NULL;
 
     if (ZSTD_isError(ZSTD_seekable_frameLog_allocVec(fl))) {
@@ -106,10 +107,9 @@ size_t ZSTD_seekable_freeFrameLog(ZSTD_frameLog* fl)
     return 0;
 }
 
-ZSTD_seekable_CStream* ZSTD_seekable_createCStream()
+ZSTD_seekable_CStream* ZSTD_seekable_createCStream(void)
 {
-    ZSTD_seekable_CStream* zcs = malloc(sizeof(ZSTD_seekable_CStream));
-
+    ZSTD_seekable_CStream* const zcs = malloc(sizeof(ZSTD_seekable_CStream));
     if (zcs == NULL) return NULL;
 
     memset(zcs, 0, sizeof(*zcs));
@@ -134,7 +134,6 @@ size_t ZSTD_seekable_freeCStream(ZSTD_seekable_CStream* zcs)
     ZSTD_freeCStream(zcs->cstream);
     ZSTD_seekable_frameLog_freeVec(&zcs->framelog);
     free(zcs);
-
     return 0;
 }
 
@@ -152,9 +151,8 @@ size_t ZSTD_seekable_initCStream(ZSTD_seekable_CStream* zcs,
         return ERROR(frameParameter_unsupported);
     }
 
-    zcs->maxFrameSize = maxFrameSize
-                                ? maxFrameSize
-                                : ZSTD_SEEKABLE_MAX_FRAME_DECOMPRESSED_SIZE;
+    zcs->maxFrameSize = maxFrameSize ?
+                        maxFrameSize : ZSTD_SEEKABLE_MAX_FRAME_DECOMPRESSED_SIZE;
 
     zcs->framelog.checksumFlag = checksumFlag;
     if (zcs->framelog.checksumFlag) {
@@ -224,8 +222,7 @@ size_t ZSTD_seekable_endFrame(ZSTD_seekable_CStream* zcs, ZSTD_outBuffer* output
     zcs->frameDSize = 0;
 
     ZSTD_CCtx_reset(zcs->cstream, ZSTD_reset_session_only);
-    if (zcs->framelog.checksumFlag)
-        XXH64_reset(&zcs->xxhState, 0);
+    if (zcs->framelog.checksumFlag) XXH64_reset(&zcs->xxhState, 0);
 
     return 0;
 }
index cf9e3dad5e09fe7c083b93af3d7674398b1d4fe6..6cb9e03fc8b95687bf7553daa3a5528452e0624e 100644 (file)
@@ -107,7 +107,8 @@ typedef struct {
 
 static int ZSTD_seekable_read_buff(void* opaque, void* buffer, size_t n)
 {
-    buffWrapper_t* buff = (buffWrapper_t*) opaque;
+    buffWrapper_t* const buff = (buffWrapper_t*)opaque;
+    assert(buff != NULL);
     if (buff->pos + n > buff->size) return -1;
     memcpy(buffer, (const BYTE*)buff->ptr + buff->pos, n);
     buff->pos += n;
@@ -118,6 +119,7 @@ static int ZSTD_seekable_seek_buff(void* opaque, long long offset, int origin)
 {
     buffWrapper_t* const buff = (buffWrapper_t*) opaque;
     unsigned long long newOffset;
+    assert(buff != NULL);
     assert(offset >= 0);
     switch (origin) {
     case SEEK_SET:
@@ -174,8 +176,7 @@ struct ZSTD_seekable_s {
 
 ZSTD_seekable* ZSTD_seekable_create(void)
 {
-    ZSTD_seekable* zs = malloc(sizeof(ZSTD_seekable));
-
+    ZSTD_seekable* const zs = malloc(sizeof(ZSTD_seekable));
     if (zs == NULL) return NULL;
 
     /* also initializes stage to zsds_init */
@@ -208,7 +209,7 @@ ZSTD_seekTable* ZSTD_seekTable_create_fromSeekable(const ZSTD_seekable* zs)
     st->tableLen = zs->seekTable.tableLen;
 
     /* Allocate an extra entry at the end to match logic of initial allocation */
-    size_t entriesSize = sizeof(seekEntry_t) * (zs->seekTable.tableLen + 1);
+    size_t const entriesSize = sizeof(seekEntry_t) * (zs->seekTable.tableLen + 1);
     seekEntry_t* const entries = (seekEntry_t*)malloc(entriesSize);
     if (entries==NULL) {
         free(st);
@@ -244,7 +245,7 @@ unsigned ZSTD_seekTable_offsetToFrameIndex(const ZSTD_seekTable* st, unsigned lo
     assert(st->tableLen <= UINT_MAX);
 
     if (pos >= st->entries[st->tableLen].dOffset) {
-        return (U32)st->tableLen;
+        return (unsigned)st->tableLen;
     }
 
     while (lo + 1 < hi) {
@@ -333,8 +334,7 @@ static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
         /* check reserved bits */
         if ((checksumFlag >> 2) & 0x1f) {
             return ERROR(corruption_detected);
-        }
-    }
+    }   }
 
     {   U32 const numFrames = MEM_readLE32(zs->inBuff);
         U32 const sizePerEntry = 8 + (checksumFlag?4:0);
@@ -342,12 +342,9 @@ static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
         U32 const frameSize = tableSize + ZSTD_seekTableFooterSize + ZSTD_SKIPPABLEHEADERSIZE;
 
         U32 remaining = frameSize - ZSTD_seekTableFooterSize; /* don't need to re-read footer */
-        {
-            U32 const toRead = MIN(remaining, SEEKABLE_BUFF_SIZE);
-
+        {   U32 const toRead = MIN(remaining, SEEKABLE_BUFF_SIZE);
             CHECK_IO(src.seek(src.opaque, -(S64)frameSize, SEEK_END));
             CHECK_IO(src.read(src.opaque, zs->inBuff, toRead));
-
             remaining -= toRead;
         }
 
@@ -360,19 +357,15 @@ static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
 
         {   /* Allocate an extra entry at the end so that we can do size
              * computations on the last element without special case */
-            seekEntry_t* entries = (seekEntry_t*)malloc(sizeof(seekEntry_t) * (numFrames + 1));
+            seekEntry_t* const entries = (seekEntry_t*)malloc(sizeof(seekEntry_t) * (numFrames + 1));
 
             U32 idx = 0;
             U32 pos = 8;
 
-
             U64 cOffset = 0;
             U64 dOffset = 0;
 
-            if (!entries) {
-                free(entries);
-                return ERROR(memory_allocation);
-            }
+            if (entries == NULL) return ERROR(memory_allocation);
 
             /* compute cumulative positions */
             for (; idx < numFrames; idx++) {