printf("Timed out, %d/%d bytes sent.\n", result, size);
/* Allocate a buffer to receive data. */
- char buf[size + 1];
+ char *buf = malloc(size + 1);
/* Try to receive the data on the other port. */
printf("Receiving %d bytes on port %s.\n",
size, sp_get_port_name(rx_port));
- check(sp_blocking_read(rx_port, buf, size, timeout));
+ result = check(sp_blocking_read(rx_port, buf, size, timeout));
/* Check whether we received the number of bytes we wanted. */
if (result == size)
/* Check if we received the same data we sent. */
buf[result] = '\0';
printf("Received '%s'.\n", buf);
+
+ /* Free receive buffer. */
+ free(buf);
}
/* Close ports and free resources. */