shithub: neindaw

Download patch

ref: ba18faf7a066bfceea07e5b03493536676fefd90
parent: 4286237ddc77dfc00b156a9a2414936beb304e90
author: Sigrid Haflínudóttir <[email protected]>
date: Mon Dec 30 19:27:06 EST 2019

fix out of range checks

--- a/README.md
+++ b/README.md
@@ -68,7 +68,6 @@
  * optional frame offsets for all commands, perhaps that's easier than
    running and stopping the processing all the time
  * `reset` command for groups
- * forbid writing values that are out of min/max range: return an error
  * add writable `metadata` for each instance
  * allow adding new key/values to `metadata`
  * add some way to read and write the whole configuration of an instance
--- a/uiglue.c
+++ b/uiglue.c
@@ -48,6 +48,7 @@
 static int
 ui_write(Aux *a, UI *ui, int type, char *s)
 {
+	int failoor;
 	float v;
 
 	if (type != Xuictl)
@@ -56,6 +57,7 @@
 	/* FIXME optional argument should specify at which frame to apply the change */
 
 	v = 0.0f;
+	failoor = 0;
 	if (strncmp(s, "reset", 5) == 0) { /* FIXME reset for a box should reset ALL controls inside it */
 		v = ui->init;
 	} else if (strncmp(s, "add", 3) == 0) {
@@ -66,15 +68,21 @@
 			v = *ui->zone - atof(s+3);
 	} else {
 		v = atof(s);
+		failoor = 1;
 	}
 
 	if (ui->zone != nil) {
-		if (a->type == UIButton || a->type == UICheckBox)
+		if (a->type == UIButton || a->type == UICheckBox) {
 			v = !!v;
-		else if (*ui->zone < ui->min)
+		} else if (v < ui->min) {
+			if (failoor)
+				return -1;
 			v = ui->min;
-		else if (*ui->zone > ui->max)
+		} else if (v > ui->max) {
+			if (failoor)
+				return -1;
 			v = ui->max;
+		}
 		*ui->zone = v;
 	}