• Nnamdi's avatar
    Stop CreateUninitializedVector returning a pointer to invalid memory. · 039ab48b
    Nnamdi authored
    CreateUninitializedVector was performing the following actions:
        1. call StartVector.
        2. call make_space, and set buf to point to the reserved space.
        3. call EndVector.
    
    The problem is that a call to EndVector can ultimately call make_space, which
    if the buffer is full, will cause a reallocation, invalidating the value stored
    in buf.  So setting buf needs to be delayed until after EndVector.
    
    The following code, when run under valgrind shows a write to free'd memory before
    the change, but no such error after:
    
    int main()
    {
        flatbuffers::FlatBufferBuilder fbb(128);
        char *buf = nullptr;
        fbb.CreateUninitializedVector(128, &buf);
        *buf = 0;
    }
    039ab48b
Name
Last commit
Last update
CMake Loading commit data...
android Loading commit data...
biicode Loading commit data...
build_ide Loading commit data...
docs Loading commit data...
go Loading commit data...
include/flatbuffers Loading commit data...
java Loading commit data...
js Loading commit data...
net/FlatBuffers Loading commit data...
php Loading commit data...
python Loading commit data...
reflection Loading commit data...
samples Loading commit data...
src Loading commit data...
tests Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.travis.yml Loading commit data...
CMakeLists.txt Loading commit data...
CONTRIBUTING Loading commit data...
LICENSE.txt Loading commit data...
biicode.conf Loading commit data...
composer.json Loading commit data...
readme.md Loading commit data...