Skip to content

Commit

Permalink
Don't use variable length c-style array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed May 27, 2015
1 parent 23a2da1 commit a0107d5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rct/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ void Connection::onDataAvailable(const SocketClient::SharedPtr&, Buffer&& buf)
assert(mPendingRead >= 0);
if (available < static_cast<unsigned int>(mPendingRead))
break;
char buffer[mPendingRead];

char staticBuf[1024 * 16];
char *buffer = static_cast<size_t>(mPendingRead) > sizeof(staticBuf) ? new char[mPendingRead] : staticBuf;
const int read = bufferRead(mBuffers, buffer, mPendingRead);
assert(read == mPendingRead);
mPendingRead = 0;
Expand All @@ -180,6 +182,8 @@ void Connection::onDataAvailable(const SocketClient::SharedPtr&, Buffer&& buf)
} else {
::error() << "Unable to create message from data" << read;
}
if (buffer != staticBuf)
delete[] buffer;
if (!message)
mSocketClient->close();
// mClient->dataAvailable().disconnect(this, &Connection::dataAvailable);
Expand Down

0 comments on commit a0107d5

Please sign in to comment.