shithub: orca

Download patch

ref: a52a95b4c703124ac5a876904d69233aa26f5726
parent: 18e8675003170f4a2251872b3f6188c2a7c2e9da
author: cancel <cancel@cancel.fm>
date: Sat Dec 8 14:11:31 EST 2018

Fix padding math error

--- a/osc_out.c
+++ b/osc_out.c
@@ -47,7 +47,7 @@
                             Usz in_str_len) {
   // no overflow check, should be fine
   Usz in_plus_null = in_str_len + 1;
-  Usz null_pad = in_plus_null % 4;
+  Usz null_pad = (4 - in_plus_null % 4) % 4;
   Usz needed = in_plus_null + null_pad;
   Usz cur_pos = *buffer_pos;
   if (cur_pos + needed >= buffer_size)
@@ -56,7 +56,7 @@
     buffer[cur_pos + i] = in_str[i];
   }
   buffer[cur_pos + in_str_len] = 0;
-  cur_pos += in_str_len;
+  cur_pos += in_plus_null;
   for (Usz i = 0; i < null_pad; ++i) {
     buffer[cur_pos + i] = 0;
   }
@@ -72,7 +72,7 @@
                        strlen(osc_address)))
     return;
   Usz typetag_str_size = 1 + count + 1; // comma, 'i'... , null
-  Usz typetag_str_null_pad = typetag_str_size % 4;
+  Usz typetag_str_null_pad = (4 - typetag_str_size % 4) % 4;
   if (buf_pos + typetag_str_size + typetag_str_null_pad > sizeof(buffer))
     return;
   buffer[buf_pos] = ',';
@@ -97,7 +97,7 @@
     pun.i = vals[i];
     U32 u_ne = htonl(pun.u);
     memcpy(buffer + buf_pos, &u_ne, sizeof(u_ne));
+    buf_pos += sizeof(u_ne);
   }
-  buf_pos += count;
   oosc_send_datagram(dev, buffer, buf_pos);
 }