summaryrefslogtreecommitdiff
path: root/src/vehicle_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/vehicle_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/vehicle_gui.cpp')
-rw-r--r--src/vehicle_gui.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 0cb5307d9..2aa2f193e 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -506,6 +506,8 @@ uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
if (!HasBit(cmask, cid)) continue;
+ if (b >= lastof(_userstring) - (2 + 2 * 4)) break; // ", " and two calls to Utf8Encode()
+
if (!first) b = strecpy(b, ", ", lastof(_userstring));
first = false;
@@ -515,6 +517,10 @@ uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
/* Terminate and display the completed string */
*b = '\0';
+
+ /* Make sure we detect any buffer overflow */
+ assert(b < endof(_userstring));
+
return DrawStringMultiLine(x, y, STR_SPEC_USERSTRING, w);
}