mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
examples/spi_slave: check for truncation in snprintf call
Also fix character array initializer
This commit is contained in:
parent
324004f7b3
commit
c3123b00ae
@ -118,8 +118,8 @@ void app_main()
|
||||
};
|
||||
|
||||
int n=0;
|
||||
char sendbuf[128]="";
|
||||
char recvbuf[128]="";
|
||||
char sendbuf[128] = {0};
|
||||
char recvbuf[128] = {0};
|
||||
spi_transaction_t t;
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
@ -143,8 +143,12 @@ void app_main()
|
||||
xSemaphoreGive(rdySem);
|
||||
|
||||
while(1) {
|
||||
snprintf(sendbuf, 128, "Sender, transmission no. %04i. Last time, I received: \"%s\"", n, recvbuf);
|
||||
t.length=128*8; //128 bytes
|
||||
int res = snprintf(sendbuf, sizeof(sendbuf),
|
||||
"Sender, transmission no. %04i. Last time, I received: \"%s\"", n, recvbuf);
|
||||
if (res >= sizeof(sendbuf)) {
|
||||
printf("Data truncated\n");
|
||||
}
|
||||
t.length=sizeof(sendbuf)*8;
|
||||
t.tx_buffer=sendbuf;
|
||||
t.rx_buffer=recvbuf;
|
||||
//Wait for slave to be ready for next byte before sending
|
||||
|
Loading…
x
Reference in New Issue
Block a user