Fix undertermined execution behavior (#4751)

Fix for the issue #4744: Ambiguous side-effect execution on vector_downward::make_space() method.
C++ does not impose evaluation order on the two expressions on the right side of the assignment, so compiler can freely decide. As ensure_space() method can change the value of "cur_" variable, the result of the subtraction may be different depending on the evaluation order, which is ambiguous in C++.
In order to make this code deterministic and correct, cur_ must be evaluated after ensure_space() is called.
This commit is contained in:
joligarson 2018-05-18 18:15:20 +02:00 committed by Wouter van Oortmerssen
parent a9640bd9e1
commit c43a0beff0
1 changed files with 2 additions and 1 deletions

View File

@ -601,7 +601,8 @@ class vector_downward {
} }
inline uint8_t *make_space(size_t len) { inline uint8_t *make_space(size_t len) {
cur_ -= ensure_space(len); size_t space = ensure_space(len);
cur_ -= space;
return cur_; return cur_;
} }