summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-08-31 18:12:43 +0000
committerSimon Howard2006-08-31 18:12:43 +0000
commit7309335cd2578e6f1bc3c69590bcc7af5840da89 (patch)
tree82fdba8f6256e308ee21ea33b3d7bce9497bcc01
parentb65d4f72edcb5e635554d68e082b6ca6c884d049 (diff)
downloadchocolate-doom-7309335cd2578e6f1bc3c69590bcc7af5840da89.tar.gz
chocolate-doom-7309335cd2578e6f1bc3c69590bcc7af5840da89.tar.bz2
chocolate-doom-7309335cd2578e6f1bc3c69590bcc7af5840da89.zip
Bomb out with an error when a dehacked string is set that is longer than
is possible in Vanilla Doom with normal dehacked. Chocolate Doom is unforgiving! Subversion-branch: /trunk/chocolate-doom Subversion-revision: 580
-rw-r--r--src/deh_text.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/deh_text.c b/src/deh_text.c
index ad61613a..3ba44031 100644
--- a/src/deh_text.c
+++ b/src/deh_text.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: deh_text.c 314 2006-01-22 21:17:56Z fraggle $
+// $Id: deh_text.c 580 2006-08-31 18:12:43Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -168,6 +168,26 @@ static void DEH_AddToHashtable(deh_substitution_t *sub)
++hash_table_entries;
}
+// Given a string length, find the maximum length of a
+// string that can replace it.
+
+static int TXT_MaxStringLength(int len)
+{
+ // Enough bytes for the string and the NUL terminator
+
+ len += 1;
+
+ // All strings in doom.exe are on 4-byte boundaries, so we may be able
+ // to support a slightly longer string.
+ // Extend up to the next 4-byte boundary
+
+ len += (4 - (len % 4)) % 4;
+
+ // Less one for the NUL terminator.
+
+ return len - 1;
+}
+
static void DEH_TextInit(void)
{
// init hash table
@@ -191,6 +211,16 @@ static void *DEH_TextStart(deh_context_t *context, char *line)
return NULL;
}
+ // Only allow string replacements that are possible in Vanilla Doom.
+ // Chocolate Doom is unforgiving!
+
+ if (tolen > TXT_MaxStringLength(fromlen))
+ {
+ DEH_Error(context, "Replacement string is longer than the maximum "
+ "possible in doom.exe");
+ return NULL;
+ }
+
sub = Z_Malloc(sizeof(deh_substitution_t), PU_STATIC, NULL);
sub->from_text = Z_Malloc(fromlen + 1, PU_STATIC, NULL);
sub->to_text = Z_Malloc(tolen + 1, PU_STATIC, NULL);
@@ -205,6 +235,7 @@ static void *DEH_TextStart(deh_context_t *context, char *line)
sub->from_text[i] = c;
}
+
sub->from_text[fromlen] = '\0';
// read in the "to" text