multprec.cpp: _MP_Rem has apparently nonsense memory read · Issue #1008 · microsoft/STL (original) (raw)

Consider this line:

if (qh < maxVal && qh * v[n - 2] <= (rh << shift) + u[j + n - 2]) {

This is reported as buggy by PREfast:

warning C6385: Reading invalid data from 'v': the readable size is '16' bytes, but '-8' bytes may be read.

I think PREfast may be correct (because v is an unsigned long long[2]) but don't understand this well enough right now to figure out why this might be OK; if it is OK, we should replace v[n - 2] with v[0] since 2 is the only value of n that doesn't trigger underflow here.