summaryrefslogtreecommitdiff
path: root/src/misc_gui.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2007-12-08 18:50:39 +0000
committersmatz <smatz@openttd.org>2007-12-08 18:50:39 +0000
commit2a62aa1ccda7ab0e8c8774f75f50210ff4dd6480 (patch)
tree0b95686d855b933403c898b7a6c165b5ec2c2f09 /src/misc_gui.cpp
parentb47bce651e64ddeab722f599c0a682281b626c45 (diff)
downloadopenttd-2a62aa1ccda7ab0e8c8774f75f50210ff4dd6480.tar.xz
(svn r11601) -Codechange: more strict break conditions for _userstring, assert when it overflows anyway (eg. code change without proper check change)
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r--src/misc_gui.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 47780867c..81dd3db97 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -772,7 +772,7 @@ static void DrawStationCoverageText(const AcceptedCargo accepts,
b = InlineString(b, STR_000D_ACCEPTS);
for (CargoID i = 0; i < NUM_CARGO; i++) {
- if (b >= lastof(_userstring) - 5) break;
+ if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
switch (sct) {
case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
@@ -795,6 +795,10 @@ static void DrawStationCoverageText(const AcceptedCargo accepts,
if (first) b = InlineString(b, STR_00D0_NOTHING);
*b = '\0';
+
+ /* Make sure we detect any buffer overflow */
+ assert(b < endof(_userstring));
+
DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
}