]> sigrok.org Git - libserialport.git/commitdiff
Fix use of variable length array in send_receive example, for MSVC.
authorMartin Ling <redacted>
Fri, 7 Feb 2020 14:09:06 +0000 (14:09 +0000)
committerMartin Ling <redacted>
Fri, 7 Feb 2020 14:09:06 +0000 (14:09 +0000)
examples/send_receive.c

index e1aabf002c0b4b99ba7785b1e3ffbd3e6218ded6..5e9f38121546780b2f4da77d3fb8e7b6a2110c35 100644 (file)
@@ -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. */