lib: zstd: Mark expected switch fall-throughs
PATCH 1/1 lib: zstd: Mark expected switch fall-throughs
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.
This patch fixes the following warnings:
lib/zstd/bitstream.h:261:30: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/bitstream.h:262:30: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/bitstream.h:263:30: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/bitstream.h:264:30: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/bitstream.h:265:30: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/compress.c:3183:16: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/decompress.c:1770:18: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/decompress.c:2376:15: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/decompress.c:2404:15: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/decompress.c:2435:16: warning: this statement may fall through [-Wimplicit-fallthrough=] lib/zstd/huf_compress.c: In function ‘HUF_compress1X_usingCTable’:lib/zstd/huf_compress.c:535:5: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 4 + 7) \
^
lib/zstd/huf_compress.c:558:54: note: in expansion of macro ‘HUF_FLUSHBITS_2’
case 3: HUF_encodeSymbol(&bitC, ip[n + 2], CTable); HUF_FLUSHBITS_2(&bitC);
^~~~~~~~~~~~~~~lib/zstd/huf_compress.c:559:2: note: here
case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC); ^~~~lib/zstd/huf_compress.c:531:5: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 2 + 7) \
^
lib/zstd/huf_compress.c:559:54: note: in expansion of macro ‘HUF_FLUSHBITS_1’
case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC);
^~~~~~~~~~~~~~~lib/zstd/huf_compress.c:560:2: note: here
case 1: HUF_encodeSymbol(&bitC, ip[n + 0], CTable); HUF_FLUSHBITS(&bitC); ^~~~
AR lib/zstd//built-in.a
Warning level 3 was used: -Wimplicit-fallthrough=3
This patch is part of the ongoing efforts to enabling -Wimplicit-fallthrough.
--- lib/zstd/bitstream.h | 5 +++++ lib/zstd/compress.c | 1 + lib/zstd/decompress.c | 5 ++++- lib/zstd/huf_compress.c | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-)
lib/zstd/bitstream.h +5 -0
@@ -259,10 +259,15 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s bitD->bitContainer = *(const BYTE *)(bitD->start);switch (srcSize) {case 7 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[6 ]) << (sizeof (bitD->bitContainer) *8 -16 ); +/* fall through */ case 6 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[5 ]) << (sizeof (bitD->bitContainer) *8 -24 ); +/* fall through */ case 5 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[4 ]) << (sizeof (bitD->bitContainer) *8 -32 ); +/* fall through */ case 4 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[3 ]) <<24 ; +/* fall through */ case 3 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[2 ]) <<16 ; +/* fall through */ case 2 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[1 ]) <<8 ;default :; }
lib/zstd/compress.c +1 -0
@@ -3182,6 +3182,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * zcs->outBuffFlushedSize =0 ; zcs->stage = zcss_flush;/* pass-through to flush stage */ } +/* fall through */ case zcss_flush: {size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;
lib/zstd/decompress.c +4 -1
@@ -1768,6 +1768,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, creturn 0 ; } dctx->expected =0 ;/* not necessary to copy more */ +/* fall through */ case ZSTDds_decodeFrameHeader:memcpy (dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected);
@@ -2375,7 +2376,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB } zds->stage = zdss_read; } -/* pass-through */ +/* fall through */ case zdss_read: {size_t const neededInSize =ZSTD_nextSrcSizeToDecompress (zds->dctx);
@@ -2404,6 +2405,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB zds->stage = zdss_load;/* pass-through */ } +/* fall through */ case zdss_load: {size_t const neededInSize =ZSTD_nextSrcSizeToDecompress (zds->dctx);
@@ -2436,6 +2438,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB/* pass-through */ } } +/* fall through */ case zdss_flush: {size_t const toFlushSize = zds->outEnd - zds->outStart;
lib/zstd/huf_compress.c +2 -0
@@ -556,7 +556,9 @@ size_t HUF_compress1X_usingCTable(void *dst, size_t dstSize, const void *src, si n = srcSize & ~3 ;/* join to mod 4 */ switch (srcSize &3 ) {case 3 :HUF_encodeSymbol (&bitC, ip[n +2 ], CTable);HUF_FLUSHBITS_2 (&bitC); +/* fall through */ case 2 :HUF_encodeSymbol (&bitC, ip[n +1 ], CTable);HUF_FLUSHBITS_1 (&bitC); +/* fall through */ case 1 :HUF_encodeSymbol (&bitC, ip[n +0 ], CTable);HUF_FLUSHBITS (&bitC);case 0 :default :;
Signature · 1 line
2.20.1
Quoted 74 lines · Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.
This patch fixes the following warnings:
lib/zstd/bitstream.h:261:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:262:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:263:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:264:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:265:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/compress.c:3183:16: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:1770:18: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2376:15: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2404:15: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2435:16: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/huf_compress.c: In function ‘HUF_compress1X_usingCTable’:lib/zstd/huf_compress.c:535:5: warning: this statement may fall through [-Wimplicit-fallthrough=]if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 4 + 7) \ ^ lib/zstd/huf_compress.c:558:54: note: in expansion of macro ‘HUF_FLUSHBITS_2’ case 3: HUF_encodeSymbol(&bitC, ip[n + 2], CTable); HUF_FLUSHBITS_2(&bitC); ^~~~~~~~~~~~~~~
lib/zstd/huf_compress.c:559:2: note: here
case 2:HUF_encodeSymbol(&bitC, ip[n + 1], CTable);HUF_FLUSHBITS_1(&bitC); ^~~~lib/zstd/huf_compress.c:531:5: warning: this statement may fall through [-Wimplicit-fallthrough=]if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 2 + 7) \ ^ lib/zstd/huf_compress.c:559:54: note: in expansion of macro ‘HUF_FLUSHBITS_1’ case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC); ^~~~~~~~~~~~~~~
lib/zstd/huf_compress.c:560:2: note: here
case 1:HUF_encodeSymbol(&bitC, ip[n + 0], CTable);HUF_FLUSHBITS(&bitC); ^~~~
AR lib/zstd//built-in.aWarning level 3 was used: -Wimplicit-fallthrough=3
This patch is part of the ongoing efforts to enabling -Wimplicit-fallthrough.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- lib/zstd/bitstream.h | 5 +++++ lib/zstd/compress.c | 1 + lib/zstd/decompress.c | 5 ++++- lib/zstd/huf_compress.c | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-)lib/zstd/bitstream.h +5
-0@@ -259,10 +259,15 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s bitD->bitContainer = *(const BYTE *)(bitD->start);switch (srcSize) {case 7 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[6 ]) << (sizeof (bitD->bitContainer) *8 -16 ); +/* fall through */ case 6 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[5 ]) << (sizeof (bitD->bitContainer) *8 -24 ); +/* fall through */ case 5 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[4 ]) << (sizeof (bitD->bitContainer) *8 -32 ); +/* fall through */ case 4 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[3 ]) <<24 ; +/* fall through */ case 3 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[2 ]) <<16 ; +/* fall through */ case 2 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[1 ]) <<8 ;default :; }lib/zstd/compress.c +0
-0
lib/zstd/compress.c static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * · line 3185
Quoted 4 lines
lib/zstd/compress.c +1
-0@@ -3182,6 +3182,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * zcs->outBuffFlushedSize =0 ; zcs->stage = zcss_flush;/* pass-through to flush stage */ } +/* fall through */
Perhaps reword the existing comment and move it down?
Quoted 25 lines
lib/zstd/compress.c +0
-0case zcss_flush: {size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;lib/zstd/decompress.c +2
-1@@ -1768,6 +1768,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, creturn 0 ; } dctx->expected =0 ;/* not necessary to copy more */ +/* fall through */ case ZSTDds_decodeFrameHeader:memcpy (dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected);@@ -2375,7 +2376,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB } zds->stage = zdss_read; } -/* pass-through */ +/* fall through */ case zdss_read: {size_t const neededInSize =ZSTD_nextSrcSizeToDecompress (zds->dctx);
lib/zstd/decompress.c size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB · line 2408
Quoted 4 lines
lib/zstd/decompress.c +1
-0@@ -2404,6 +2405,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB zds->stage = zdss_load;/* pass-through */ } +/* fall through */
Same ("pass-through" exists a couple lines up)
lib/zstd/decompress.c size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB · line 2441
Quoted 8 lines
lib/zstd/decompress.c +1
-0case zdss_load: {size_t const neededInSize =ZSTD_nextSrcSizeToDecompress (zds->dctx);@@ -2436,6 +2438,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB/* pass-through */ } } +/* fall through */
Same
Quoted 18 lines
lib/zstd/decompress.c +0
-0case zdss_flush: {size_t const toFlushSize = zds->outEnd - zds->outStart;lib/zstd/huf_compress.c +2
-1@@ -556,7 +556,9 @@ size_t HUF_compress1X_usingCTable(void *dst, size_t dstSize, const void *src, si n = srcSize & ~3 ;/* join to mod 4 */ switch (srcSize &3 ) {case 3 :HUF_encodeSymbol (&bitC, ip[n +2 ], CTable);HUF_FLUSHBITS_2 (&bitC); +/* fall through */ case 2 :HUF_encodeSymbol (&bitC, ip[n +1 ], CTable);HUF_FLUSHBITS_1 (&bitC); +/* fall through */ case 1 :HUF_encodeSymbol (&bitC, ip[n +0 ], CTable);HUF_FLUSHBITS (&bitC);case 0 :default :; --
Quoted 2 lines
2.20.1
Otherwise, yup, looks good.
Signature · 1 line
Kees Cook
Quoted 116 lines · Kees Cook
Quoted 74 lines · Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.
This patch fixes the following warnings:
lib/zstd/bitstream.h:261:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:262:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:263:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:264:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:265:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/compress.c:3183:16: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:1770:18: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2376:15: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2404:15: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2435:16: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/huf_compress.c: In function ‘HUF_compress1X_usingCTable’:lib/zstd/huf_compress.c:535:5: warning: this statement may fall through [-Wimplicit-fallthrough=]if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 4 + 7) \ ^ lib/zstd/huf_compress.c:558:54: note: in expansion of macro ‘HUF_FLUSHBITS_2’ case 3: HUF_encodeSymbol(&bitC, ip[n + 2], CTable); HUF_FLUSHBITS_2(&bitC); ^~~~~~~~~~~~~~~
lib/zstd/huf_compress.c:559:2: note: here
case 2:HUF_encodeSymbol(&bitC, ip[n + 1], CTable);HUF_FLUSHBITS_1(&bitC); ^~~~lib/zstd/huf_compress.c:531:5: warning: this statement may fall through [-Wimplicit-fallthrough=]if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 2 + 7) \ ^ lib/zstd/huf_compress.c:559:54: note: in expansion of macro ‘HUF_FLUSHBITS_1’ case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC); ^~~~~~~~~~~~~~~
lib/zstd/huf_compress.c:560:2: note: here
case 1:HUF_encodeSymbol(&bitC, ip[n + 0], CTable);HUF_FLUSHBITS(&bitC); ^~~~
AR lib/zstd//built-in.aWarning level 3 was used: -Wimplicit-fallthrough=3
This patch is part of the ongoing efforts to enabling -Wimplicit-fallthrough.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- lib/zstd/bitstream.h | 5 +++++ lib/zstd/compress.c | 1 + lib/zstd/decompress.c | 5 ++++- lib/zstd/huf_compress.c | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-)lib/zstd/bitstream.h +5
-0@@ -259,10 +259,15 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s bitD->bitContainer = *(const BYTE *)(bitD->start);switch (srcSize) {case 7 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[6 ]) << (sizeof (bitD->bitContainer) *8 -16 ); +/* fall through */ case 6 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[5 ]) << (sizeof (bitD->bitContainer) *8 -24 ); +/* fall through */ case 5 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[4 ]) << (sizeof (bitD->bitContainer) *8 -32 ); +/* fall through */ case 4 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[3 ]) <<24 ; +/* fall through */ case 3 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[2 ]) <<16 ; +/* fall through */ case 2 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[1 ]) <<8 ;default :; }lib/zstd/compress.c +0
-0lib/zstd/compress.c static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * · line 3185
Quoted 4 lines
lib/zstd/compress.c +1
-0@@ -3182,6 +3182,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * zcs->outBuffFlushedSize =0 ; zcs->stage = zcss_flush;/* pass-through to flush stage */ } +/* fall through */ Perhaps reword the existing comment and move it down?
Quoted 25 lines
lib/zstd/compress.c +0
-0case zcss_flush: {size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;lib/zstd/decompress.c +2
-1@@ -1768,6 +1768,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, creturn 0 ; } dctx->expected =0 ;/* not necessary to copy more */ +/* fall through */ case ZSTDds_decodeFrameHeader:memcpy (dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected);@@ -2375,7 +2376,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB } zds->stage = zdss_read; } -/* pass-through */ +/* fall through */ case zdss_read: {size_t const neededInSize =ZSTD_nextSrcSizeToDecompress (zds->dctx);lib/zstd/decompress.c size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB · line 2408
Quoted 4 lines
lib/zstd/decompress.c +1
-0@@ -2404,6 +2405,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB zds->stage = zdss_load;/* pass-through */ } +/* fall through */ Same ("pass-through" exists a couple lines up)
Quoted 1 line
Quoted 9 lines
lib/zstd/decompress.c size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB · line 2441
Quoted 7 lines
case zdss_load: { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds->dctx);lib/zstd/decompress.c +1
-0@@ -2436,6 +2438,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB/* pass-through */ } } +/* fall through */ Same
Yeah. The thing is that the pass-though comment is embedded in two nested blocks of code. And GCC triggers a warning if the fall-through comments are not placed at the very bottom of the case statement (some people dislike this 'feature').
That's the reason why I didn't want to change any of the pass-through comments, and instead added the fall-through comments at the bottom of every case.
What do you think about this 'feature'?
Quoted 24 lines
Quoted 19 lines
lib/zstd/decompress.c +0
-0case zdss_flush: {size_t const toFlushSize = zds->outEnd - zds->outStart;lib/zstd/huf_compress.c +2
-1@@ -556,7 +556,9 @@ size_t HUF_compress1X_usingCTable(void *dst, size_t dstSize, const void *src, si n = srcSize & ~3 ;/* join to mod 4 */ switch (srcSize &3 ) {case 3 :HUF_encodeSymbol (&bitC, ip[n +2 ], CTable);HUF_FLUSHBITS_2 (&bitC); +/* fall through */ case 2 :HUF_encodeSymbol (&bitC, ip[n +1 ], CTable);HUF_FLUSHBITS_1 (&bitC); +/* fall through */ case 1 :HUF_encodeSymbol (&bitC, ip[n +0 ], CTable);HUF_FLUSHBITS (&bitC);case 0 :default :; --Quoted 2 lines
2.20.1
Otherwise, yup, looks good.
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
Thanks
--
Gustavo
Quoted 130 lines · Gustavo A. R. Silva
Quoted 116 lines · Kees Cook
Quoted 74 lines · Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.
This patch fixes the following warnings:
lib/zstd/bitstream.h:261:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:262:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:263:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:264:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/bitstream.h:265:30: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/compress.c:3183:16: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:1770:18: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2376:15: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2404:15: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/decompress.c:2435:16: warning: this statement may fall through [-Wimplicit-fallthrough=]lib/zstd/huf_compress.c: In function ‘HUF_compress1X_usingCTable’:lib/zstd/huf_compress.c:535:5: warning: this statement may fall through [-Wimplicit-fallthrough=]if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 4 + 7) \ ^ lib/zstd/huf_compress.c:558:54: note: in expansion of macro ‘HUF_FLUSHBITS_2’ case 3: HUF_encodeSymbol(&bitC, ip[n + 2], CTable); HUF_FLUSHBITS_2(&bitC); ^~~~~~~~~~~~~~~
lib/zstd/huf_compress.c:559:2: note: here
case 2:HUF_encodeSymbol(&bitC, ip[n + 1], CTable);HUF_FLUSHBITS_1(&bitC); ^~~~lib/zstd/huf_compress.c:531:5: warning: this statement may fall through [-Wimplicit-fallthrough=]if (sizeof((stream)->bitContainer) * 8 < HUF_TABLELOG_MAX * 2 + 7) \ ^ lib/zstd/huf_compress.c:559:54: note: in expansion of macro ‘HUF_FLUSHBITS_1’ case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC); ^~~~~~~~~~~~~~~
lib/zstd/huf_compress.c:560:2: note: here
case 1:HUF_encodeSymbol(&bitC, ip[n + 0], CTable);HUF_FLUSHBITS(&bitC); ^~~~
AR lib/zstd//built-in.aWarning level 3 was used: -Wimplicit-fallthrough=3
This patch is part of the ongoing efforts to enabling -Wimplicit-fallthrough.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- lib/zstd/bitstream.h | 5 +++++ lib/zstd/compress.c | 1 + lib/zstd/decompress.c | 5 ++++- lib/zstd/huf_compress.c | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-)lib/zstd/bitstream.h +5
-0@@ -259,10 +259,15 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s bitD->bitContainer = *(const BYTE *)(bitD->start);switch (srcSize) {case 7 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[6 ]) << (sizeof (bitD->bitContainer) *8 -16 ); +/* fall through */ case 6 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[5 ]) << (sizeof (bitD->bitContainer) *8 -24 ); +/* fall through */ case 5 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[4 ]) << (sizeof (bitD->bitContainer) *8 -32 ); +/* fall through */ case 4 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[3 ]) <<24 ; +/* fall through */ case 3 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[2 ]) <<16 ; +/* fall through */ case 2 : bitD->bitContainer += (size_t )(((const BYTE *)(srcBuffer))[1 ]) <<8 ;default :; }lib/zstd/compress.c +0
-0lib/zstd/compress.c static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * · line 3185
Quoted 4 lines
lib/zstd/compress.c +1
-0@@ -3182,6 +3182,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, void *dst, size_t * zcs->outBuffFlushedSize =0 ; zcs->stage = zcss_flush;/* pass-through to flush stage */ } +/* fall through */ Perhaps reword the existing comment and move it down?
Quoted 25 lines
lib/zstd/compress.c +0
-0case zcss_flush: {size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;lib/zstd/decompress.c +2
-1@@ -1768,6 +1768,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, creturn 0 ; } dctx->expected =0 ;/* not necessary to copy more */ +/* fall through */ case ZSTDds_decodeFrameHeader:memcpy (dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected);@@ -2375,7 +2376,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB } zds->stage = zdss_read; } -/* pass-through */ +/* fall through */ case zdss_read: {size_t const neededInSize =ZSTD_nextSrcSizeToDecompress (zds->dctx);lib/zstd/decompress.c size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB · line 2408
Quoted 4 lines
lib/zstd/decompress.c +1
-0@@ -2404,6 +2405,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB zds->stage = zdss_load;/* pass-through */ } +/* fall through */ Same ("pass-through" exists a couple lines up)
Quoted 1 line
Quoted 9 lines
lib/zstd/decompress.c size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB · line 2441
Quoted 7 lines
case zdss_load: { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds->dctx);lib/zstd/decompress.c +1
-0@@ -2436,6 +2438,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB/* pass-through */ } } +/* fall through */ Same
Quoted 6 lines
Yeah. The thing is that the pass-though comment is embedded in two nested blocks of code. And GCC triggers a warning if the fall-through comments are not placed at the very bottom of the case statement (some people dislike this 'feature').
That's the reason why I didn't want to change any of the pass-through comments, and instead added the fall-through comments at the bottom of every case.
Okay, that seems fine. Good as-is, then! :)
-Kees
Quoted 34 lines
What do you think about this 'feature'?
Quoted 24 lines
Quoted 19 lines
lib/zstd/decompress.c +0
-0case zdss_flush: {size_t const toFlushSize = zds->outEnd - zds->outStart;lib/zstd/huf_compress.c +2
-1@@ -556,7 +556,9 @@ size_t HUF_compress1X_usingCTable(void *dst, size_t dstSize, const void *src, si n = srcSize & ~3 ;/* join to mod 4 */ switch (srcSize &3 ) {case 3 :HUF_encodeSymbol (&bitC, ip[n +2 ], CTable);HUF_FLUSHBITS_2 (&bitC); +/* fall through */ case 2 :HUF_encodeSymbol (&bitC, ip[n +1 ], CTable);HUF_FLUSHBITS_1 (&bitC); +/* fall through */ case 1 :HUF_encodeSymbol (&bitC, ip[n +0 ], CTable);HUF_FLUSHBITS (&bitC);case 0 :default :; --Quoted 2 lines
2.20.1
Otherwise, yup, looks good.
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>Thanks
--
Gustavo
Signature · 1 line
Kees Cook