Closed
Description
In the Rustonomicon example code for implementing Vec
, the first version of the grow
method to increase capacity includes a bounds check to ensure that the new capacity is not an integer overflow, but when grow
is reimplemented in later sections this check is omitted.
Specifically, in the section named "Allocating Memory", the method grow
is implemented for Vec
which includes the following line:
// Long comment explaining this assertion
assert!(old_num_bytes <= (::std::isize::MAX as usize) / 2,
"capacity overflow");
However, in the sections "RawVec" and "The Final Code", this same method is implemented for RawVec
, but the implementation does not contain this line or any equivalent functionality. This means that these later versions might behave incorrectly when the capacity reaches memory limits.
Metadata
Metadata
Assignees
Labels
No labels