stun: Use dynamic array instead of stack allocated array
authorDavid Feurle <david.feurle@sodgeit.de>
Sat, 7 Feb 2015 09:49:07 +0000 (10:49 +0100)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Wed, 11 Feb 2015 12:37:17 +0000 (12:37 +0000)
Dynamic on-stack arrays are not supported in Visual Studio.

This has the downside of introducing an extra memory allocation into
libstun, but it’s on a debug path so should be harmless.

stun/debug.c

index f3a55bb..3d579db 100644 (file)
@@ -79,11 +79,12 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
 {
   size_t i;
   size_t prefix_len = strlen (prefix);
-  char bytes[prefix_len + 2 + (len * 2) + 1];
+  char *bytes;
 
   if (!debug_enabled)
     return;
 
+  bytes = malloc (prefix_len + 2 + (len * 2) + 1);
   bytes[0] = 0;
   strcpy (bytes, prefix);
   strcpy (bytes + prefix_len, "0x");
@@ -92,6 +93,7 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
     sprintf (bytes + prefix_len + 2 + (i * 2), "%02x", ((const unsigned char *)data)[i]);
 
   stun_debug ("%s", bytes);
+  free (bytes);
 }