[quake3-commits] r1688 - trunk/code/botlib

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Oct 19 19:29:45 EDT 2009


Author: thilo
Date: 2009-10-19 19:29:44 -0400 (Mon, 19 Oct 2009)
New Revision: 1688

Modified:
   trunk/code/botlib/be_ai_weight.c
   trunk/code/botlib/l_precomp.c
   trunk/code/botlib/l_script.c
Log:
Fix botlib parser for negative int/float values, thanks to Makro for reporting (#4227).


Modified: trunk/code/botlib/be_ai_weight.c
===================================================================
--- trunk/code/botlib/be_ai_weight.c	2009-10-19 23:01:00 UTC (rev 1687)
+++ trunk/code/botlib/be_ai_weight.c	2009-10-19 23:29:44 UTC (rev 1688)
@@ -64,13 +64,20 @@
 	if (!strcmp(token.string, "-"))
 	{
 		SourceWarning(source, "negative value set to zero\n");
-		if (!PC_ExpectTokenType(source, TT_NUMBER, 0, &token)) return qfalse;
-	} //end if
+
+		if(!PC_ExpectAnyToken(source, &token))
+		{
+			SourceError(source, "Missing return value\n");
+			return qfalse;
+		}
+	}
+
 	if (token.type != TT_NUMBER)
 	{
 		SourceError(source, "invalid return value %s\n", token.string);
 		return qfalse;
-	} //end if
+	}
+	
 	*value = token.floatvalue;
 	return qtrue;
 } //end of the function ReadValue

Modified: trunk/code/botlib/l_precomp.c
===================================================================
--- trunk/code/botlib/l_precomp.c	2009-10-19 23:01:00 UTC (rev 1687)
+++ trunk/code/botlib/l_precomp.c	2009-10-19 23:29:44 UTC (rev 1688)
@@ -2561,12 +2561,16 @@
 	sprintf(token.string, "%d", abs(value));
 	token.type = TT_NUMBER;
 	token.subtype = TT_INTEGER|TT_LONG|TT_DECIMAL;
+
 #ifdef NUMBERVALUE
-	token.intvalue = value;
-	token.floatvalue = value;
+	token.intvalue = abs(value);
+	token.floatvalue = token.intvalue;
 #endif //NUMBERVALUE
+
 	PC_UnreadSourceToken(source, &token);
-	if (value < 0) UnreadSignToken(source);
+	if (value < 0)
+		UnreadSignToken(source);
+
 	return qtrue;
 } //end of the function PC_DollarDirective_evalint
 //============================================================================
@@ -2588,12 +2592,16 @@
 	sprintf(token.string, "%1.2f", fabs(value));
 	token.type = TT_NUMBER;
 	token.subtype = TT_FLOAT|TT_LONG|TT_DECIMAL;
+
 #ifdef NUMBERVALUE
-	token.intvalue = (unsigned long) value;
-	token.floatvalue = value;
+	token.floatvalue = fabs(value);
+	token.intvalue = (unsigned long) token.floatvalue;
 #endif //NUMBERVALUE
+
 	PC_UnreadSourceToken(source, &token);
-	if (value < 0) UnreadSignToken(source);
+	if (value < 0)
+		UnreadSignToken(source);
+
 	return qtrue;
 } //end of the function PC_DollarDirective_evalfloat
 //============================================================================

Modified: trunk/code/botlib/l_script.c
===================================================================
--- trunk/code/botlib/l_script.c	2009-10-19 23:01:00 UTC (rev 1687)
+++ trunk/code/botlib/l_script.c	2009-10-19 23:29:44 UTC (rev 1688)
@@ -1156,13 +1156,21 @@
 	PS_ExpectAnyToken(script, &token);
 	if (!strcmp(token.string, "-"))
 	{
+		if(!PS_ExpectAnyToken(script, &token))
+		{
+			ScriptError(script, "Missing float value\n", token.string);
+			return 0;
+		}
+
 		sign = -1.0;
-		PS_ExpectTokenType(script, TT_NUMBER, 0, &token);
-	} //end if
-	else if (token.type != TT_NUMBER)
+	}
+	
+	if (token.type != TT_NUMBER)
 	{
 		ScriptError(script, "expected float value, found %s\n", token.string);
-	} //end else if
+		return 0;
+	}
+
 	return sign * token.floatvalue;
 } //end of the function ReadSignedFloat
 //============================================================================
@@ -1179,13 +1187,21 @@
 	PS_ExpectAnyToken(script, &token);
 	if (!strcmp(token.string, "-"))
 	{
+		if(!PS_ExpectAnyToken(script, &token))
+		{
+			ScriptError(script, "Missing integer value\n", token.string);
+			return 0;
+		}
+
 		sign = -1;
-		PS_ExpectTokenType(script, TT_NUMBER, TT_INTEGER, &token);
-	} //end if
-	else if (token.type != TT_NUMBER || token.subtype == TT_FLOAT)
+	}
+
+	if (token.type != TT_NUMBER || token.subtype == TT_FLOAT)
 	{
 		ScriptError(script, "expected integer value, found %s\n", token.string);
-	} //end else if
+		return 0;
+	}
+	
 	return sign * token.intvalue;
 } //end of the function ReadSignedInt
 //============================================================================



More information about the quake3-commits mailing list