examples/spi_slave: check for truncation in snprintf call

Also fix character array initializer
pull/2351/head
Ivan Grokhotkov 2018-08-28 21:34:44 +08:00
rodzic 324004f7b3
commit c3123b00ae
1 zmienionych plików z 8 dodań i 4 usunięć

Wyświetl plik

@ -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