dmx: bugfix argv[0] = 0 on command, limits on set
authorTero Marttila <terom@paivola.fi>
Fri, 11 Apr 2014 19:03:49 +0300
changeset 67 53743ecc9150
parent 66 0cf14786b909
child 68 be139319a961
dmx: bugfix argv[0] = 0 on command, limits on set
src/hello-dmx.c
--- a/src/hello-dmx.c	Fri Apr 11 15:57:48 2014 +0300
+++ b/src/hello-dmx.c	Fri Apr 11 19:03:49 2014 +0300
@@ -83,7 +83,7 @@
 {
     byte i;
 
-    for (i = 0; i < console.argc; i++) {
+    for (i = 0; i < console.argc && i < DMX_COUNT; i++) {
         dmx.out[i] = console.argv[i];
     }
 
@@ -101,14 +101,19 @@
         return '!';
     }
 
-    byte i = console.argv[0];
+    if (console.argv[0] == 0) {
+        return '!';
+    }
 
-    for (byte a = 1; a < console.argc; a++) {
+    byte i = console.argv[0] - 1;
+
+    for (byte a = 1; a < console.argc && i < DMX_COUNT; a++) {
         dmx.out[i++] = console.argv[a];
     }
 
-    if (i > dmx.count)
+    if (i > dmx.count) {
         dmx.count = i;
+    }
 
     return 0;
 }
@@ -187,6 +192,7 @@
         if (console.state == CMD) {
             console.state = ARG;
             console.argc = 0;
+            console.argv[0] = 0;
 
             return ',';