From 251890e3b9393ddb968345e04aa29b1ca7aee410 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 7 Feb 2020 14:09:06 +0000 Subject: [PATCH] Fix use of variable length array in send_receive example, for MSVC. --- examples/send_receive.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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. */