Browse Source

Bugfix: Make curses_input return NULL on a blank line, as most callers expect

Luke Dashjr 12 years ago
parent
commit
081a48fe0a
2 changed files with 15 additions and 5 deletions
  1. 2 0
      adl.c
  2. 13 5
      miner.c

+ 2 - 0
adl.c

@@ -922,6 +922,8 @@ static float curses_float(const char *query)
 	char *cvar;
 
 	cvar = curses_input(query);
+	if (unlikely(!cvar))
+		return -1;
 	ret = atof(cvar);
 	free(cvar);
 	return ret;

+ 13 - 5
miner.c

@@ -5949,6 +5949,8 @@ int curses_int(const char *query)
 	char *cvar;
 
 	cvar = curses_input(query);
+	if (unlikely(!cvar))
+		return -1;
 	ret = atoi(cvar);
 	free(cvar);
 	return ret;
@@ -6669,6 +6671,11 @@ retry:
 		goto updated;
         } else if (!strncasecmp(&input, "p", 1)) {
 			char *prilist = curses_input("Enter new pool priority (comma separated list)");
+			if (!prilist)
+			{
+				wlogprint("Not changing priorities\n");
+				goto retry;
+			}
 			int res = prioritize_pools(prilist, &i);
 			free(prilist);
 			switch (res) {
@@ -6893,7 +6900,7 @@ retry:
 		default_save_file(filename);
 		snprintf(prompt, sizeof(prompt), "Config filename to write (Enter for default) [%s]", filename);
 		str = curses_input(prompt);
-		if (strcmp(str, "-1")) {
+		if (str) {
 			struct stat statbuf;
 
 			strcpy(filename, str);
@@ -6905,8 +6912,6 @@ retry:
 					goto retry;
 			}
 		}
-		else
-			free(str);
 		fcfg = fopen(filename, "w");
 		if (!fcfg) {
 			wlogprint("Cannot open or create file\n");
@@ -7081,7 +7086,7 @@ refresh:
 			{
 				static char *pattern = NULL;
 				char *newpattern = curses_input("Enter pattern");
-				if (strcmp(newpattern, "-1"))
+				if (newpattern)
 				{
 					free(pattern);
 					pattern = newpattern;
@@ -9804,7 +9809,10 @@ char *curses_input(const char *query)
 	wlogprint("%s:\n", query);
 	wgetnstr(logwin, input, 255);
 	if (!strlen(input))
-		strcpy(input, "-1");
+	{
+		free(input);
+		input = NULL;
+	}
 	leaveok(logwin, true);
 	noecho();
 	return input;