changeset 1837:15dc26825b55 draft

(svn r2342) - Fix (Regression): _cmd_text is always valid, so test the first character for '\0'. Also for some reason I forgot to validate the p1 param so that might lead to crashes with invalid signes. Fixed as well.
author Darkvater <Darkvater@openttd.org>
date Tue, 17 May 2005 19:36:36 +0000
parents 8f8d84cb13a7
children 925fb6fd2fb5
files signs.c signs.h
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/signs.c
+++ b/signs.c
@@ -136,9 +136,11 @@
  */
 int32 CmdRenameSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 {
-	/* If _cmd_text != 0 means the new text for the sign is non-empty.
+	if (!IsSignIndex(p1)) return CMD_ERROR;
+
+	/* If _cmd_text 0 means the new text for the sign is non-empty.
 	 * So rename the sign. If it is empty, it has no name, so delete it */
-	if (_cmd_text != NULL) {
+	if (_cmd_text[0] != '\0') {
 		/* Create the name */
 		StringID str = AllocateName(_cmd_text, 0);
 		if (str == 0) return CMD_ERROR;
--- a/signs.h
+++ b/signs.h
@@ -41,6 +41,11 @@
 	return _sign_pool.total_items;
 }
 
+static inline bool IsSignIndex(uint index)
+{
+	return index < GetSignPoolSize();
+}
+
 #define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1 < GetSignPoolSize()) ? GetSign(ss->index + 1) : NULL)
 #define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)