strengthen compilation flags

dev
Yann Collet 2021-03-02 15:43:52 -08:00
parent c7e42e147b
commit 029f974ddc
5 changed files with 16 additions and 14 deletions

View File

@ -16,7 +16,8 @@ ZSTDLIB = $(ZSTDLIB_PATH)/$(ZSTDLIB_NAME)
CPPFLAGS += -I../ -I$(ZSTDLIB_PATH) -I$(ZSTDLIB_PATH)/common CPPFLAGS += -I../ -I$(ZSTDLIB_PATH) -I$(ZSTDLIB_PATH)/common
CFLAGS ?= -O3 CFLAGS ?= -O3
CFLAGS += -g CFLAGS += -g -Wall -Wextra -Wcast-qual -Wcast-align -Wconversion \
-Wformat=2 -Wstrict-aliasing=1
SEEKABLE_OBJS = ../zstdseek_compress.c ../zstdseek_decompress.c $(ZSTDLIB) SEEKABLE_OBJS = ../zstdseek_compress.c ../zstdseek_decompress.c $(ZSTDLIB)
@ -33,6 +34,6 @@ $(ZSTDLIB):
seekable_tests : seekable_tests.c $(SEEKABLE_OBJS) seekable_tests : seekable_tests.c $(SEEKABLE_OBJS)
clean: clean:
@rm -f core *.o tmp* result* *.zst \ @$(RM) core *.o tmp* result* *.zst \
seekable_tests seekable_tests
@echo Cleaning completed @echo Cleaning completed

View File

@ -8,6 +8,7 @@
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
unsigned testNb = 1; unsigned testNb = 1;
(void)argc; (void)argv;
printf("Beginning zstd seekable format tests...\n"); printf("Beginning zstd seekable format tests...\n");
printf("Test %u - check that seekable decompress does not hang: ", testNb++); printf("Test %u - check that seekable decompress does not hang: ", testNb++);
{ /* Github issue #2335 */ { /* Github issue #2335 */

View File

@ -173,7 +173,7 @@ ZSTDLIB_API unsigned ZSTD_seekable_offsetToFrameIndex(const ZSTD_seekable* zs, u
/*===== Independent seek table management =====*/ /*===== Independent seek table management =====*/
ZSTDLIB_API size_t ZSTD_seekable_copySeekTable(ZSTD_seekable* zs, ZSTD_seekTable** out); ZSTDLIB_API ZSTD_seekTable* ZSTD_seekTable_create_fromSeekable(const ZSTD_seekable* zs);
ZSTDLIB_API size_t ZSTD_seekTable_free(ZSTD_seekTable* st); ZSTDLIB_API size_t ZSTD_seekTable_free(ZSTD_seekTable* st);
/*===== Direct seek table access functions =====*/ /*===== Direct seek table access functions =====*/

View File

@ -118,15 +118,16 @@ static int ZSTD_seekable_seek_buff(void* opaque, long long offset, int origin)
{ {
buffWrapper_t* const buff = (buffWrapper_t*) opaque; buffWrapper_t* const buff = (buffWrapper_t*) opaque;
unsigned long long newOffset; unsigned long long newOffset;
assert(offset >= 0);
switch (origin) { switch (origin) {
case SEEK_SET: case SEEK_SET:
newOffset = offset; newOffset = (unsigned long long)offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
newOffset = (unsigned long long)buff->pos + offset; newOffset = (unsigned long long)buff->pos + (unsigned long long)offset;
break; break;
case SEEK_END: case SEEK_END:
newOffset = (unsigned long long)buff->size + offset; newOffset = (unsigned long long)buff->size + (unsigned long long)offset;
break; break;
default: default:
assert(0); /* not possible */ assert(0); /* not possible */
@ -198,10 +199,10 @@ size_t ZSTD_seekable_free(ZSTD_seekable* zs)
return 0; return 0;
} }
size_t ZSTD_seekable_copySeekTable(ZSTD_seekable* zs, ZSTD_seekTable** out) ZSTD_seekTable* ZSTD_seekTable_create_fromSeekable(const ZSTD_seekable* zs)
{ {
ZSTD_seekTable* const st = malloc(sizeof(ZSTD_seekTable)); ZSTD_seekTable* const st = malloc(sizeof(ZSTD_seekTable));
if (st==NULL) return ERROR(memory_allocation); if (st==NULL) return NULL;
st->checksumFlag = zs->seekTable.checksumFlag; st->checksumFlag = zs->seekTable.checksumFlag;
st->tableLen = zs->seekTable.tableLen; st->tableLen = zs->seekTable.tableLen;
@ -211,14 +212,12 @@ size_t ZSTD_seekable_copySeekTable(ZSTD_seekable* zs, ZSTD_seekTable** out)
seekEntry_t* const entries = (seekEntry_t*)malloc(entriesSize); seekEntry_t* const entries = (seekEntry_t*)malloc(entriesSize);
if (entries==NULL) { if (entries==NULL) {
free(st); free(st);
return ERROR(memory_allocation); return NULL;
} }
memcpy(entries, zs->seekTable.entries, entriesSize); memcpy(entries, zs->seekTable.entries, entriesSize);
st->entries = entries; st->entries = entries;
return st;
*out = st;
return 0;
} }
size_t ZSTD_seekTable_free(ZSTD_seekTable* st) size_t ZSTD_seekTable_free(ZSTD_seekTable* st)
@ -449,8 +448,9 @@ size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t len, unsign
zs->decompressedOffset = zs->seekTable.entries[targetFrame].dOffset; zs->decompressedOffset = zs->seekTable.entries[targetFrame].dOffset;
zs->curFrame = targetFrame; zs->curFrame = targetFrame;
assert(zs->seekTable.entries[targetFrame].cOffset < LLONG_MAX);
CHECK_IO(zs->src.seek(zs->src.opaque, CHECK_IO(zs->src.seek(zs->src.opaque,
zs->seekTable.entries[targetFrame].cOffset, (long long)zs->seekTable.entries[targetFrame].cOffset,
SEEK_SET)); SEEK_SET));
zs->in = (ZSTD_inBuffer){zs->inBuff, 0, 0}; zs->in = (ZSTD_inBuffer){zs->inBuff, 0, 0};
XXH64_reset(&zs->xxhState, 0); XXH64_reset(&zs->xxhState, 0);

View File

@ -308,7 +308,7 @@ MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
MEM_STATIC U32 MEM_readLE24(const void* memPtr) MEM_STATIC U32 MEM_readLE24(const void* memPtr)
{ {
return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16); return (U32)MEM_readLE16(memPtr) + ((U32)(((const BYTE*)memPtr)[2]) << 16);
} }
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val) MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)