artf4106: ISO C++ forbids variable-size array

C++14 changed the definition of VLAs, so the previous usage was no longer valid ISO C++. GCC 5.1.0 actually enforces this definition, so this commit fixes the build under GCC 5.1.0. This also builds under GCC 4.9.1.

Change-Id: Ib5ae2c49b4c4c21455b722b6633d7841066b4872
This commit is contained in:
Tyler Veness
2015-06-23 19:16:28 -07:00
committed by Tyler Veness (3512)
parent b5695581c3
commit f96b61ef11
3 changed files with 8 additions and 17 deletions

View File

@@ -1,9 +1,5 @@
#include "networktables2/connection/DataIOStream.h"
//TODO remove this when alloca is solved
#ifdef WIN32
#include <malloc.h>
#endif
#include <memory>
///This is used in case NULL is passed so all logic calls to IOstream can continue to assume there is never a null pointer
class InertStream : public IOStream
@@ -73,14 +69,8 @@ uint16_t DataIOStream::read2BytesBE()
}
std::string* DataIOStream::readString()
{
unsigned int byteLength = read2BytesBE();
#ifndef WIN32
uint8_t bytes[byteLength+1];//FIXME figure out why this doesn't work on windows
#else
uint8_t* bytes = (uint8_t*)alloca(byteLength+1);
#endif
iostream->read(bytes, byteLength);
bytes[byteLength] = 0;
return new std::string((char*)bytes);//FIXME implement UTF-8 aware version
auto bytes = std::make_unique<char[]>(byteLength);
iostream->read(bytes.get(), byteLength);
return new std::string(bytes.get());//FIXME implement UTF-8 aware version
}