shithub: cflood

Download patch

ref: 172d631819e492f3392a97ea4e78e0231f475c22
parent: 506526148adb2e34a68daf30116accf9c5b53c9b
author: Sigrid Solveig Haflínudóttir <248148+ftrvxmtrx@users.noreply.github.com>
date: Tue Dec 18 19:51:06 EST 2012

games/cflood: fix crash on invalid arguments; fix clickwait after fail->new; exits(nil)

--- a/games/cflood.c
+++ b/games/cflood.c
@@ -205,6 +205,7 @@
 	state = Tgame;
 	size = sizes[sid];
 	turnsleft = turns[sid];
+	clickwait = 0;
 
 	if(cells == nil){
 		maxsize = (size > sizes[Slarge]) ? size : sizes[Slarge];
@@ -266,10 +267,14 @@
 	case 's':
 		sid = Scustom;
 		sizes[sid] = atoi(ARGF());
+		if(sizes[sid] < 1)
+			usage();
 		break;
 	case 't':
 		sid = Scustom;
 		turns[sid] = atoi(ARGF());
+		if(turns[sid] < 1)
+			usage();
 		break;
 	default:
 		usage();
@@ -291,7 +296,6 @@
 			else if(p > 0)
 				break;
 		}else if(clickwait && !oldbuttons && m.buttons){
-			clickwait = 0;
 			newgame(sid);
 		}else if(m.buttons & 1){
 			for(i = 0; i < NumColors; i++){
@@ -304,4 +308,6 @@
 
 		oldbuttons = m.buttons;
 	}
+
+	exits(nil);
 }