HomePhabricator

Avoid undefined behavior using CFlatData in CScript serialization
fa126effc2a0Unpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

Avoid undefined behavior using CFlatData in CScript serialization

&vch[vch.size()] and even &vch[0] on vectors can cause assertion
errors with VC in debug mode. This is the problem mentioned in #4239.
The deeper problem with this is that we rely on undefined behavior.

  • Add begin_ptr and end_ptr functions that get the beginning and end pointer of vector in a reliable way that copes with empty vectors and doesn't reference outside the vector

(see https://stackoverflow.com/questions/1339470/how-to-get-the-address-of-the-stdvector-buffer-start-most-elegantly/1339767#1339767).

  • Add a convenience constructor to CFlatData that wraps a vector.

I added begin_ptr and end_ptr as separate functions as I imagine
they will be useful in more places.

Details

Provenance
Wladimir J. van der Laan <laanwj@gmail.com>Authored on Jun 5 2014, 08:10
deadalnixPushed on May 14 2017, 22:04
Parents
rABC52d4abfdef93: Merge pull request #4388
Branches
Unknown
Tags
Unknown

Event Timeline

Wladimir J. van der Laan <laanwj@gmail.com> committed rABCfa126effc2a0: Avoid undefined behavior using CFlatData in CScript serialization (authored by Wladimir J. van der Laan <laanwj@gmail.com>).Jun 23 2014, 08:38