From: Martin Ling Date: Fri, 7 Feb 2020 14:09:06 +0000 (+0000) Subject: Fix use of variable length array in send_receive example, for MSVC. X-Git-Tag: libserialport-0.1.2~19 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=251890e3b9393ddb968345e04aa29b1ca7aee410;p=libserialport.git Fix use of variable length array in send_receive example, for MSVC. --- diff --git a/examples/send_receive.c b/examples/send_receive.c index e1aabf0..5e9f381 100644 --- a/examples/send_receive.c +++ b/examples/send_receive.c @@ -81,7 +81,7 @@ int main(int argc, char **argv) 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", @@ -97,6 +97,9 @@ int main(int argc, char **argv) /* 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. */