libCuba: guard memcpy in SobolIni against negative length
GCC's -Wstringop-overflow flagged the memcpy in SobolIni() with a bound of (size_t)(-4): on the (in practice unreachable) path where the Sobol generator polynomial 'powers' is 0, the bit-count loop leaves inibits at its initial -1, so inibits*sizeof underflows. The generator-polynomial table always has a non-zero first column, so this never happens at run time, but the compiler cannot prove it. Guard the copy with 'if (inibits > 0)', which silences the false-positive warning and hardens the edge case without changing behaviour for valid input. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -102,7 +102,8 @@ static inline void SobolIni(This *t)
|
||||
int inibits = -1, bit;
|
||||
for( j = powers; j; j >>= 1 ) ++inibits;
|
||||
|
||||
memcpy(pv, pini, inibits*sizeof *pini);
|
||||
if( inibits > 0 )
|
||||
memcpy(pv, pini, inibits*sizeof *pini);
|
||||
pini += 8;
|
||||
|
||||
for( bit = inibits; bit <= nbits; ++bit ) {
|
||||
|
||||
Reference in New Issue
Block a user