Commit c905b104 authored by Ian McInerney's avatar Ian McInerney

Fixed array access error

parent f1346345
......@@ -66,15 +66,24 @@ void CCrazyflie::callback_Packet(CCRTPPacket *crtpPacket) {
// See if the length is 0, if it is leave
break;
}
char *cText;
// Allocate space for the text array and a null terminator
char *cText;
cText = (char*) std::malloc(nLength + 1);
if (cText == NULL) {
// Memory allocation failed
break;
}
// Copy the data and add a null terminator
std::memcpy(cText, &cData[0], nLength);
cText[nLength + 1] = '\0';
cText[nLength] = '\0';
// Print it and flush the console
this->file_console << cText;
this->file_console.flush();
std::free(cText);
}
break;
......@@ -82,7 +91,7 @@ void CCrazyflie::callback_Packet(CCRTPPacket *crtpPacket) {
// Logging
if (crtpPacket->channel() == 2) {
CCRTPPacket *crtpLog = new CCRTPPacket(cData, nLength,
crtpPacket->channel());
crtpPacket->channel());
crtpLog->setChannel(crtpPacket->channel());
crtpLog->setPort(crtpPacket->port());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment