Open AnnaKornfeldSimpson opened 6 years ago
Another example. In this case I am not sure whether the size_t to uint32_t is casting down to a smaller numerical type.
bar ( void *outData : byte_count(outSize), // OUT: Output data
size_t outSize, // IN: Size of output data in bytes
const void *inData : byte_count(inSize), // IN: Input data
size_t inSize, // IN: Size of input data in bytes
)
{
if (outSize < inSize) {
return INVALID_PARAMETER;
}
// TODO: In this function, outsize must exactly == inSize. Dynamic bounds cast needed to shrink
// Since the length inSize is cast to uint32_t in the next function call, need to explicitly cast the bounds as well. This is a pain.
_Array_ptr<void> tmpOutData : byte_count((uint32_t)inSize) = _Dynamic_bounds_cast<_Array_ptr<void>>(outData, byte_count((uint32_t)inSize));
_Array_ptr<void> tmpInData : byte_count((uint32_t)inSize) = _Dynamic_bounds_cast<_Array_ptr<void>>(inData, byte_count((uint32_t)inSize));
OpOn32BitLens(tmpInData, tmpOutData, (uint32_t)inSize);
}
This issue got automatically closed by mistake: GitHub closed issue number N in the checkedc-clang
repository when a 3C PR that has a comment "Fixes issue N" (where N refers to the issue number in CCI's repository), was merged to master
branch in the checkedc-clang
repository. Reopening it.
In the following code snippet, why am I required to explicitly cast
freespace
to asize_t
when defining the bounds for the args to memcpy? If I do not, it gives me a cannot prove bounds warning where the only difference between expected and inferred bounds is that the expected bounds have a(size_t)
cast in front offreespace
.freespace
is already unsigned, it should be able to implicitly convert tosize_t
. The same behavior occurs when the length is auint32_t
instead of anunsigned int
.Note: This bug definitely occurs on Linux and I'm pretty sure also on Windows. Both should be using 64-bit versions of checkedc-clang.