Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The end pointer is positioned one past the end of the destination, and it is undefined behavior to compute an address beyond the end pointer, including for comparisons, even temporarily. The UB occurs exactly when buffer overflow would have occurred, so the buffer overflow check could be optimized away by compilers. Even if this wasn't the case, the check could produce a false negative if the computed address overflowed the address space, which is, after all, why the C standard doesn't define behavior in the first place. The fix is simple: Check using sizes, not addresses. The explicit cast suppresses warnings about signed-unsigned comparisons, and the assertion checks the cast.
- Loading branch information