dmx: fill: actually enforce end, don't overrun if fill sequence is longer
authorTero Marttila <terom@paivola.fi>
Fri, 11 Apr 2014 20:46:25 +0300
changeset 72 2957be8573b9
parent 71 24f00b561a4a
child 73 3c25f32c92fa
dmx: fill: actually enforce end, don't overrun if fill sequence is longer
src/hello-dmx.c
--- a/src/hello-dmx.c	Fri Apr 11 19:51:19 2014 +0300
+++ b/src/hello-dmx.c	Fri Apr 11 20:46:25 2014 +0300
@@ -140,12 +140,17 @@
         return '!';
     }
 
+    if (end >= DMX_COUNT) {
+        return '!';
+    }
+
     // apply
     // arg is 1..256
     byte c = start - 1;
 
-    for ( ; c < end && c < DMX_COUNT - 1; ) {
-        for (byte a = 2; a < console.argc && c < DMX_COUNT - 1; a++) {
+    // c < end actually means inclusive to end of range, as the index is -1
+    for ( ; c < end; ) {
+        for (byte a = 2; a < console.argc && c < end; a++) {
             dmx.out[c++] = console.argv[a];
         }
     }