lib: zstd: Fix Wstringop-overflow warning
PATCH 1/1 lib: zstd: Fix Wstringop-overflow warning
Fix the following -Wstringop-overflow warning when building with GCC-11:
lib/zstd/decompress/huf_decompress.c: In function ‘HUF_readDTableX2_wksp’:lib/zstd/decompress/huf_decompress.c:700:5: warning: ‘HUF_fillDTableX2.constprop’ accessing 624 bytes in a region of size 52 [-Wstringop-overflow=]
700 | HUF_fillDTableX2(dt, maxTableLog,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
701 | wksp->sortedSymbol, sizeOfSort,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
702 | wksp->rankStart0, wksp->rankVal, maxW,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
703 | tableLog+1,
| ~~~~~~~~~~~
704 | wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/zstd/decompress/huf_decompress.c:700:5: note: referencing argument 6 of type ‘U32 (*)[13]’ {aka ‘unsigned int (*)[13]’}
lib/zstd/decompress/huf_decompress.c:571:13: note: in a call to function ‘HUF_fillDTableX2.constprop’
571 | static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
| ^~~~~~~~~~~~~~~~by using pointer notation instead of array notation.
This helps with the ongoing efforts to globally enable -Wstringop-overflow.
--- lib/zstd/decompress/huf_decompress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/zstd/decompress/huf_decompress.c +3 -3
@@ -570,7 +570,7 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 costatic void HUF_fillDTableX2 (HUF_DEltX2 * DTable,const U32 targetLog,const sortedSymbol_t * sortedList,const U32 sortedListSize, -const U32 * rankStart,rankVal_t rankValOrigin,const U32 maxWeight, +const U32 * rankStart,const U32 * rankValOrigin,const U32 maxWeight,const U32 nbBitsBaseline,U32 * wksp,size_t wkspSize) {U32 * rankVal = wksp;
@@ -598,7 +598,7 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,if (minWeight <1 ) minWeight =1 ; sortedRank = rankStart[minWeight];HUF_fillDTableX2Level2 (DTable+start, targetLog-nbBits, nbBits, - rankValOrigin[nbBits], minWeight, + rankValOrigin + nbBits, minWeight, sortedList+sortedRank, sortedListSize-sortedRank, nbBitsBaseline, symbol, wksp, wkspSize); }else {
@@ -699,7 +699,7 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,HUF_fillDTableX2 (dt, maxTableLog, wksp->sortedSymbol, sizeOfSort, - wksp->rankStart0, wksp->rankVal, maxW, + wksp->rankStart0, (U32 *)wksp->rankVal, maxW, tableLog+1 , wksp->calleeWksp,sizeof (wksp->calleeWksp) /sizeof (U32 ));
Signature · 1 line
2.27.0
Quoted 4 lines · Gustavo A. R. Silva
Fix the following -Wstringop-overflow warning when building with GCC-11:
lib/zstd/decompress/huf_decompress.c: In function ‘HUF_readDTableX2_wksp’:lib/zstd/decompress/huf_decompress.c:700:5: warning: ‘HUF_fillDTableX2.constprop’ accessing 624 bytes in a region of size 52 [-Wstringop-overflow=]
Quoted 14 lines
700 | HUF_fillDTableX2(dt, maxTableLog,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
701 | wksp->sortedSymbol, sizeOfSort,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
702 | wksp->rankStart0, wksp->rankVal, maxW,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
703 | tableLog+1,
| ~~~~~~~~~~~
704 | wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/zstd/decompress/huf_decompress.c:700:5: note: referencing argument 6 of type ‘U32 (*)[13]’ {aka ‘unsigned int (*)[13]’}
lib/zstd/decompress/huf_decompress.c:571:13: note: in a call to function ‘HUF_fillDTableX2.constprop’
571 | static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
| ^~~~~~~~~~~~~~~~Reviewing this changes would be easier if the reason for the warning could be explained. i.e. why has GCC decided that the region is 52 bytes, and how did it calculate the 624 bytes?
rankVal_t is HUF_TABLELOG_MAX-many rankValCol_t, which itself is HUF_TABLELOG_MAX + 1 many U32s. So, basically:
U32 array[HUF_TABLELOG_MAX + 1][HUF_TABLELOG_MAX]
sizeof(rankValCol_t) == 52sizeof(rankVal_t) == 624
Quoted 17 lines
by using pointer notation instead of array notation.
This helps with the ongoing efforts to globally enable -Wstringop-overflow.
--- lib/zstd/decompress/huf_decompress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)lib/zstd/decompress/huf_decompress.c +0
-0
lib/zstd/decompress/huf_decompress.c static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 co · line 574
Quoted 6 lines
lib/zstd/decompress/huf_decompress.c +1
-1@@ -570,7 +570,7 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 costatic void HUF_fillDTableX2 (HUF_DEltX2 * DTable,const U32 targetLog,const sortedSymbol_t * sortedList,const U32 sortedListSize, -const U32 * rankStart,rankVal_t rankValOrigin,const U32 maxWeight, +const U32 * rankStart,const U32 * rankValOrigin,const U32 maxWeight,const U32 nbBitsBaseline,U32 * wksp,size_t wkspSize)
This really feels like we're papering over the warning. This removes the type information and makes it a U32 * instead, and then later makes a cast?
Can this be fixed in a way that retains the type information?
On the other hand, all the arguments are also U32 *.
I see stuff like:
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));
That looks like it's ignoring type information as well. i.e. why isn't this sizeof(rankValOrigin)? (The length above is 52 bytes.)
I'm especially curious here since rankValOrigin is rankVal_t, which is 624 bytes, not 52 bytes (i.e. the above is copying a single rankValCol_t from rankValOrigin. I'd expect this to be:
ZSTD_memcpy(rankVal, &rankValOrigin[0], sizeof(rankValOrigin[0]));
lib/zstd/decompress/huf_decompress.c static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, · line 601
Quoted 8 lines
lib/zstd/decompress/huf_decompress.c +1
-1{U32 * rankVal = wksp;@@ -598,7 +598,7 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,if (minWeight <1 ) minWeight =1 ; sortedRank = rankStart[minWeight]; HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits, - rankValOrigin[nbBits], minWeight, + rankValOrigin + nbBits, minWeight,
And here I'd expect to pass &rankValOrigin[nbBits]
since HUF_fillDTableX2Level2 is doing another rankValCol_t-sized copy:
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));
lib/zstd/decompress/huf_decompress.c size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, · line 702
Quoted 9 lines
lib/zstd/decompress/huf_decompress.c +1
-1sortedList+sortedRank, sortedListSize-sortedRank, nbBitsBaseline, symbol, wksp, wkspSize); }else {@@ -699,7 +699,7 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, HUF_fillDTableX2(dt, maxTableLog, wksp->sortedSymbol, sizeOfSort, - wksp->rankStart0, wksp->rankVal, maxW, + wksp->rankStart0, (U32 *)wksp->rankVal, maxW,
It's possible the problem is with this structure:
typedef struct {
rankValCol_t rankVal[HUF_TABLELOG_MAX];
U32 rankStats[HUF_TABLELOG_MAX + 1];
U32 rankStart0[HUF_TABLELOG_MAX + 2];
sortedSymbol_t sortedSymbol[HUF_SYMBOLVALUE_MAX + 1];
BYTE weightList[HUF_SYMBOLVALUE_MAX + 1];
U32 calleeWksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
} HUF_ReadDTableX2_Workspace;it's not using the rankVal_t type for rankVal for some reason?
i.e. what's passed to HUF_fillDTableX2 is a rankValCol_t (52 bytes), but then it gets passed against later as rankVal_t (624 bytes).
Does changing the type definition above solve this more cleanly?
-Kees
Quoted 6 lines
lib/zstd/decompress/huf_decompress.c +0
-0tableLog+1 , wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32));Signature · 1 line
2.27.0
Signature · 1 line
Kees Cook
Nick Terrell
maintainerQuoted 28 lines · Kees Cook
Quoted 4 lines · Gustavo A. R. Silva
Fix the following -Wstringop-overflow warning when building with GCC-11:
lib/zstd/decompress/huf_decompress.c: In function ‘HUF_readDTableX2_wksp’:lib/zstd/decompress/huf_decompress.c:700:5: warning: ‘HUF_fillDTableX2.constprop’ accessing 624 bytes in a region of size 52 [-Wstringop-overflow=]Quoted 14 lines
700 | HUF_fillDTableX2(dt, maxTableLog, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 701 | wksp->sortedSymbol, sizeOfSort, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 702 | wksp->rankStart0, wksp->rankVal, maxW, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 703 | tableLog+1, | ~~~~~~~~~~~ 704 | wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/zstd/decompress/huf_decompress.c:700:5: note: referencing argument 6 of type ‘U32 (*)[13]’ {aka ‘unsigned int (*)[13]’} lib/zstd/decompress/huf_decompress.c:571:13: note: in a call to function ‘HUF_fillDTableX2.constprop’ 571 | static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, | ^~~~~~~~~~~~~~~~Reviewing this changes would be easier if the reason for the warning could be explained. i.e. why has GCC decided that the region is 52 bytes, and how did it calculate the 624 bytes?
Quoted 7 lines
rankVal_tis HUF_TABLELOG_MAX-manyrankValCol_t, which itself isHUF_TABLELOG_MAX+ 1 many U32s. So, basically:U32 array[HUF_TABLELOG_MAX + 1][HUF_TABLELOG_MAX]
sizeof(rankValCol_t)== 52sizeof(rankVal_t)== 624
Yeah, I'm not quite sure what this warning is saying. Clarification would be useful. It seems like a false positive to me, but I could be mistaken.
Quoted 36 lines
Quoted 17 lines
by using pointer notation instead of array notation.
This helps with the ongoing efforts to globally enable -Wstringop-overflow.
---
lib/zstd/decompress/huf_decompress.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)lib/zstd/decompress/huf_decompress.c +0
-0lib/zstd/decompress/huf_decompress.c static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 co · line 574
Quoted 6 lines
lib/zstd/decompress/huf_decompress.c +1
-1@@ -570,7 +570,7 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 costatic void HUF_fillDTableX2 (HUF_DEltX2 * DTable,const U32 targetLog,const sortedSymbol_t * sortedList,const U32 sortedListSize, -const U32 * rankStart,rankVal_t rankValOrigin,const U32 maxWeight, +const U32 * rankStart,const U32 * rankValOrigin,const U32 maxWeight,const U32 nbBitsBaseline,U32 * wksp,size_t wkspSize)This really feels like we're papering over the warning. This removes the type information and makes it a U32 * instead, and then later makes a cast?
Can this be fixed in a way that retains the type information?
On the other hand, all the arguments are also U32 *.
I see stuff like:
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));
Quoted 8 lines
That looks like it's ignoring type information as well. i.e. why isn't this sizeof(rankValOrigin)? (The length above is 52 bytes.)
I'm especially curious here since rankValOrigin is
rankVal_t, which is 624 bytes, not 52 bytes (i.e. the above is copying a singlerankValCol_tfrom rankValOrigin. I'd expect this to be:ZSTD_memcpy(rankVal, &rankValOrigin[0], sizeof(rankValOrigin[0]));
Yes, this is definitely a better way to write it. But, I think the & is unnecessary. Because of the way C arrays work, rankValOrigin == rankValOrigin[0].
Upstream, this memcpy is gone, and this code has been optimized & refactored [1]. And that will get pulled in in the next update. But, in the meantime, I'd be happy to accept a refactoring diff.
[0] https://gcc.godbolt.org/z/orodoK818
[1] https://github.com/facebook/zstd/blob/3e6bbdd8473a753d2047969ac0053fb2cb4dda23/lib/decompress/huf_decompress.c#L992-L1036
Quoted 12 lines
lib/zstd/decompress/huf_decompress.c static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, · line 601
Quoted 8 lines
lib/zstd/decompress/huf_decompress.c +1
-1{U32 * rankVal = wksp;@@ -598,7 +598,7 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,if (minWeight <1 ) minWeight =1 ; sortedRank = rankStart[minWeight]; HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits, - rankValOrigin[nbBits], minWeight, + rankValOrigin + nbBits, minWeight,And here I'd expect to pass &rankValOrigin[nbBits]
sinceHUF_fillDTableX2Level2is doing another rankValCol_t-sized copy:
Quoted 1 line
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));
In HUF_fillDTableX2Level2, rankValOrigin is a rankValCol_t. It is confusing, and this is improved upstream, though rankVal is passed as a U32 const*, where it should really Be a rankValCol_t. So I'll put up a small PR to improve that upstream.
Quoted 21 lines
lib/zstd/decompress/huf_decompress.c size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, · line 702
Quoted 9 lines
lib/zstd/decompress/huf_decompress.c +1
-1sortedList+sortedRank, sortedListSize-sortedRank, nbBitsBaseline, symbol, wksp, wkspSize); }else {@@ -699,7 +699,7 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, HUF_fillDTableX2(dt, maxTableLog, wksp->sortedSymbol, sizeOfSort, - wksp->rankStart0, wksp->rankVal, maxW, + wksp->rankStart0, (U32 *)wksp->rankVal, maxW,It's possible the problem is with this structure:
typedef struct { rankValCol_t rankVal[HUF_TABLELOG_MAX]; U32 rankStats[HUF_TABLELOG_MAX + 1]; U32 rankStart0[HUF_TABLELOG_MAX + 2]; sortedSymbol_t sortedSymbol[HUF_SYMBOLVALUE_MAX + 1]; BYTE weightList[HUF_SYMBOLVALUE_MAX + 1]; U32 calleeWksp[HUF_READ_STATS_WORKSPACE_SIZE_U32]; } HUF_ReadDTableX2_Workspace;
Quoted 6 lines
it's not using the
rankVal_ttype for rankVal for some reason?i.e. what's passed to
HUF_fillDTableX2is arankValCol_t(52 bytes), but then it gets passed against later asrankVal_t(624 bytes).Does changing the type definition above solve this more cleanly?
It would make sense to refactor it as a rankVal_t to me, since that is consistent with the function signature. However, after removing typedefs, wksp->rankVal should be exactly the same type as rankVal_t. So the warning seems too noisy here.
Not saying that the code can't be improved, it certainly can be, and I will put up a PR upstream by tomorrow, and link it here.
Best,
Nick Terrell
Quoted 11 lines
-Kees
Quoted 6 lines
lib/zstd/decompress/huf_decompress.c +0
-0tableLog+1 , wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32));Signature · 1 line
2.27.0Signature · 1 line
Kees Cook
Quoted 24 lines · Nick Terrell
Quoted 24 lines · Kees Cook
Quoted 18 lines · Gustavo A. R. Silva
Fix the following -Wstringop-overflow warning when building with GCC-11:
lib/zstd/decompress/huf_decompress.c: In function ‘HUF_readDTableX2_wksp’:lib/zstd/decompress/huf_decompress.c:700:5: warning: ‘HUF_fillDTableX2.constprop’ accessing 624 bytes in a region of size 52 [-Wstringop-overflow=]700 | HUF_fillDTableX2(dt, maxTableLog, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 701 | wksp->sortedSymbol, sizeOfSort, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 702 | wksp->rankStart0, wksp->rankVal, maxW, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 703 | tableLog+1, | ~~~~~~~~~~~ 704 | wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/zstd/decompress/huf_decompress.c:700:5: note: referencing argument 6 of type ‘U32 (*)[13]’ {aka ‘unsigned int (*)[13]’} lib/zstd/decompress/huf_decompress.c:571:13: note: in a call to function ‘HUF_fillDTableX2.constprop’ 571 | static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, | ^~~~~~~~~~~~~~~~
Quoted 8 lines
Quoted 8 lines
Reviewing this changes would be easier if the reason for the warning could be explained. i.e. why has GCC decided that the region is 52 bytes, and how did it calculate the 624 bytes?
rankVal_tis HUF_TABLELOG_MAX-manyrankValCol_t, which itself isHUF_TABLELOG_MAX+ 1 many U32s. So, basically:U32 array[HUF_TABLELOG_MAX + 1][HUF_TABLELOG_MAX]
I think this is U32 array[HUF_TABLELOG_MAX][HUF_TABLELOG_MAX + 1]
Quoted 3 lines
Quoted 3 lines
sizeof(rankValCol_t)== 52sizeof(rankVal_t)== 624
Yep;
Quoted 52 lines
Yeah, I'm not quite sure what this warning is saying. Clarification would be useful. It seems like a false positive to me, but I could be mistaken.
Quoted 36 lines
Quoted 17 lines
by using pointer notation instead of array notation.
This helps with the ongoing efforts to globally enable -Wstringop-overflow.
---
lib/zstd/decompress/huf_decompress.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)lib/zstd/decompress/huf_decompress.c +0
-0lib/zstd/decompress/huf_decompress.c static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 co · line 574
Quoted 6 lines
lib/zstd/decompress/huf_decompress.c +1
-1@@ -570,7 +570,7 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 costatic void HUF_fillDTableX2 (HUF_DEltX2 * DTable,const U32 targetLog,const sortedSymbol_t * sortedList,const U32 sortedListSize, -const U32 * rankStart,rankVal_t rankValOrigin,const U32 maxWeight, +const U32 * rankStart,const U32 * rankValOrigin,const U32 maxWeight,const U32 nbBitsBaseline,U32 * wksp,size_t wkspSize)This really feels like we're papering over the warning. This removes the type information and makes it a U32 * instead, and then later makes a cast?
Can this be fixed in a way that retains the type information?
On the other hand, all the arguments are also U32 *.
I see stuff like:
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));Quoted 8 lines
That looks like it's ignoring type information as well. i.e. why isn't this sizeof(rankValOrigin)? (The length above is 52 bytes.)
I'm especially curious here since rankValOrigin is
rankVal_t, which is 624 bytes, not 52 bytes (i.e. the above is copying a singlerankValCol_tfrom rankValOrigin. I'd expect this to be:ZSTD_memcpy(rankVal, &rankValOrigin[0], sizeof(rankValOrigin[0]));Yes, this is definitely a better way to write it. But, I think the
&is unnecessary. Because of the way C arrays work, rankValOrigin == rankValOrigin[0].
Quoted 17 lines
Upstream, this memcpy is gone, and this code has been optimized & refactored [1]. And that will get pulled in in the next update. But, in the meantime, I'd be happy to accept a refactoring diff.
[0] https://gcc.godbolt.org/z/orodoK818
[1] https://github.com/facebook/zstd/blob/3e6bbdd8473a753d2047969ac0053fb2cb4dda23/lib/decompress/huf_decompress.c#L992-L1036Quoted 10 lines
lib/zstd/decompress/huf_decompress.c static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, · line 601
Quoted 8 lines
lib/zstd/decompress/huf_decompress.c +1
-1{U32 * rankVal = wksp;@@ -598,7 +598,7 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,if (minWeight <1 ) minWeight =1 ; sortedRank = rankStart[minWeight]; HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits, - rankValOrigin[nbBits], minWeight, + rankValOrigin + nbBits, minWeight,And here I'd expect to pass &rankValOrigin[nbBits]
In this case &rankValOrigin[nbBits] (array notation) is equivalent to rankValOrigin + nbBits (pointer arithmetic notation).
Quoted 35 lines
Quoted 3 lines
since
HUF_fillDTableX2Level2is doing another rankValCol_t-sized copy:ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));In
HUF_fillDTableX2Level2, rankValOrigin is arankValCol_t. It is confusing, and this is improved upstream, though rankVal is passed as a U32 const*, where it should really Be arankValCol_t. So I'll put up a small PR to improve that upstream.Quoted 27 lines
lib/zstd/decompress/huf_decompress.c size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, · line 702
Quoted 9 lines
lib/zstd/decompress/huf_decompress.c +1
-1sortedList+sortedRank, sortedListSize-sortedRank, nbBitsBaseline, symbol, wksp, wkspSize); }else {@@ -699,7 +699,7 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, HUF_fillDTableX2(dt, maxTableLog, wksp->sortedSymbol, sizeOfSort, - wksp->rankStart0, wksp->rankVal, maxW, + wksp->rankStart0, (U32 *)wksp->rankVal, maxW,It's possible the problem is with this structure:
typedef struct { rankValCol_t rankVal[HUF_TABLELOG_MAX]; U32 rankStats[HUF_TABLELOG_MAX + 1]; U32 rankStart0[HUF_TABLELOG_MAX + 2]; sortedSymbol_t sortedSymbol[HUF_SYMBOLVALUE_MAX + 1]; BYTE weightList[HUF_SYMBOLVALUE_MAX + 1]; U32 calleeWksp[HUF_READ_STATS_WORKSPACE_SIZE_U32]; } HUF_ReadDTableX2_Workspace;it's not using the
rankVal_ttype for rankVal for some reason?i.e. what's passed to
HUF_fillDTableX2is arankValCol_t(52 bytes), but then it gets passed against later asrankVal_t(624 bytes).Does changing the type definition above solve this more cleanly?
I noticed exactly the same thing. However, changing the type definiton required extra refactoring that at that moment I wasn't sure it was the correct thing to do. So, this definitely needed some comments from the maintainer.
Quoted 8 lines
It would make sense to refactor it as a
rankVal_tto me, since that is consistent with the function signature. However, after removing typedefs,wksp->rankValshould be exactly the same type asrankVal_t. So the warning seems too noisy here.Not saying that the code can't be improved, it certainly can be, and I will put up a PR upstream by tomorrow, and link it here.
That'd be great, Nick! :)
Thank you both Kees and Nick for the feedback.
--
Gustavo