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)
|
void Transceiver::driveControl(size_t chan)
|
||||||
{
|
{
|
||||||
// check control socket
|
char buffer[MAX_PACKET_LENGTH + 1];
|
||||||
char buffer[MAX_PACKET_LENGTH];
|
char response[MAX_PACKET_LENGTH + 1];
|
||||||
int msgLen = -1;
|
int msgLen;
|
||||||
buffer[0] = '\0';
|
|
||||||
|
|
||||||
msgLen = mCtrlSockets[chan]->read(buffer, sizeof(buffer));
|
/* Attempt to read from control socket */
|
||||||
|
msgLen = mCtrlSockets[chan]->read(buffer, MAX_PACKET_LENGTH);
|
||||||
if (msgLen < 1) {
|
if (msgLen < 1)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
/* Zero-terminate received string */
|
||||||
|
buffer[msgLen] = '\0';
|
||||||
|
|
||||||
char cmdcheck[4];
|
char cmdcheck[4];
|
||||||
char command[MAX_PACKET_LENGTH];
|
char command[MAX_PACKET_LENGTH];
|
||||||
char response[MAX_PACKET_LENGTH];
|
|
||||||
|
|
||||||
sscanf(buffer,"%3s %s",cmdcheck,command);
|
sscanf(buffer,"%3s %s",cmdcheck,command);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue