Transceiver.cpp: properly zero-terminate received commands
Previously it was assumed that a sender should zero-terminate each command being sent. Otherwise, this could cause to printing garbage. Let's do this manually, using the length of received data as a position for '\0'. Change-Id: I69f413f33156c38a853efc5a8cdc66fbfb0ca6af
This commit is contained in:
parent
bd0efb0bea
commit
4d9b59c3ef
|
@ -661,20 +661,20 @@ void Transceiver::reset()
|
|||
|
||||
void Transceiver::driveControl(size_t chan)
|
||||
{
|
||||
// check control socket
|
||||
char buffer[MAX_PACKET_LENGTH];
|
||||
int msgLen = -1;
|
||||
buffer[0] = '\0';
|
||||
char buffer[MAX_PACKET_LENGTH + 1];
|
||||
char response[MAX_PACKET_LENGTH + 1];
|
||||
int msgLen;
|
||||
|
||||
msgLen = mCtrlSockets[chan]->read(buffer, sizeof(buffer));
|
||||
|
||||
if (msgLen < 1) {
|
||||
/* Attempt to read from control socket */
|
||||
msgLen = mCtrlSockets[chan]->read(buffer, MAX_PACKET_LENGTH);
|
||||
if (msgLen < 1)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Zero-terminate received string */
|
||||
buffer[msgLen] = '\0';
|
||||
|
||||
char cmdcheck[4];
|
||||
char command[MAX_PACKET_LENGTH];
|
||||
char response[MAX_PACKET_LENGTH];
|
||||
|
||||
sscanf(buffer,"%3s %s",cmdcheck,command);
|
||||
|
||||
|
|
Loading…
Reference in New Issue