From d40bc5a2649f7f5b7dda429614a290f6bbc1f69c Mon Sep 17 00:00:00 2001 From: peter1138 Date: Wed, 17 May 2006 13:05:44 +0000 Subject: [PATCH] (svn r4897) - NewGRF: don't allow addition of empty strings in action 4 --- newgrf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/newgrf.c b/newgrf.c index b17897829c..c141b7342f 100644 --- a/newgrf.c +++ b/newgrf.c @@ -1793,7 +1793,7 @@ static void VehicleNewName(byte *buf, int len) for (; id < endid && len > 0; id++) { size_t ofs = strlen(name) + 1; - if (ofs < 128) { + if (ofs > 1 && ofs < 128) { DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name); switch (feature) { @@ -1857,7 +1857,13 @@ static void VehicleNewName(byte *buf, int len) #endif } } else { - DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs); + /* ofs is the string length + 1, so if the string is empty, ofs + * is 1 */ + if (ofs == 1) { + DEBUG(grf, 7) ("VehicleNewName: Can't add empty name"); + } else { + DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs); + } } name += ofs; len -= ofs;