changeset 33:b083ddc5c546

Sanitise command line input
author Jeremy Gow <jeremy.gow@gmail.com>
date Tue, 13 Nov 2012 23:57:14 +0000
parents 01926bcd6016
children f23acab50cd3
files Experiment.class Experiment.java
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
Binary file Experiment.class has changed
--- a/Experiment.java	Tue Nov 13 18:00:31 2012 +0000
+++ b/Experiment.java	Tue Nov 13 23:57:14 2012 +0000
@@ -113,9 +113,9 @@
             showClock = false;
         else 
             showClock = true;
-        clockUnits = cu; 
-        numUnits = nu; 
-        scaleLength = sl;
+        clockUnits = positiveInteger(cu, 1); 
+	numUnits = positiveInteger(nu, 4); 
+        scaleLength = positiveInteger(sl, 7);
         midiDevice = md;
         lowAnchor = la;
         highAnchor = ha;
@@ -244,4 +244,11 @@
 	}
     }
 
+    private int positiveInteger(int x, int def) {
+	if (x > 0) 
+	    return x;
+	else
+	    return def;
+    }
+
 }