[mw-devel] MW3 r1084 - trunk/src

arthur at sucs.org arthur at sucs.org
Thu Apr 23 16:35:32 BST 2009


Author: arthur
Date: 2009-04-23 16:35:32 +0100 (Thu, 23 Apr 2009)
New Revision: 1084

Modified:
   trunk/src/newmain.c
Log:
limit unit characters that can be used in timeout, fixes #44


Modified: trunk/src/newmain.c
===================================================================
--- trunk/src/newmain.c	2009-04-15 00:43:17 UTC (rev 1083)
+++ trunk/src/newmain.c	2009-04-23 15:35:32 UTC (rev 1084)
@@ -840,17 +840,32 @@
 
 void c_timeout(CommandList *cm, int argc, char **argv, char *args)
 {
-	int z=atoi(argv[1]);
+	int z;
 	int units=1;
+	char *s = NULL;
+	z=strtol(argv[1], &s, 10);
 
-	if (strchr(argv[1],'m') || strchr(argv[1],'M'))
+	/* no number found */
+	if (s == argv[1]) {
+		printf(_("TIMEOUT must be at least 10 minutes.\n"));
+		return;
+	}
+
+	if (*s == '\0' || strchr("sS", *s))
+		units = 1;
+	else
+	if (strchr("mM",*s))
 		units = 60;
 	else
-	if (strchr(argv[1],'h') || strchr(argv[1],'H'))
+	if (strchr("hH",*s))
 		units = 3600;
 	else
-	if (strchr(argv[1],'d') || strchr(argv[1],'D'))
+	if (strchr("dD",*s))
 		units = 86400;
+	else {
+		printf(_("Invalid time unit '%c' must be one of: dhms.\n"), *s);
+		return;
+	}
 
 	z *= units;
 




More information about the mw-devel mailing list