summaryrefslogtreecommitdiff
path: root/misc_gui.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-11-06 15:25:02 +0000
committerpeter1138 <peter1138@openttd.org>2006-11-06 15:25:02 +0000
commit701c47fb4aa37466552102be487f5938daad0c69 (patch)
tree14d27e1fa0b04e593a00ca91c8c3cc98645ab0a9 /misc_gui.c
parent3da04ab1b5db262df37156b5da5de8a2cf072a87 (diff)
downloadopenttd-701c47fb4aa37466552102be487f5938daad0c69.tar.xz
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
Diffstat (limited to 'misc_gui.c')
-rw-r--r--misc_gui.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/misc_gui.c b/misc_gui.c
index 2db97dac2..4ebe9edd6 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -715,25 +715,29 @@ static void DrawStationCoverageText(const AcceptedCargo accepts,
int str_x, int str_y, uint mask)
{
char *b = _userstring;
+ bool first = true;
int i;
b = InlineString(b, STR_000D_ACCEPTS);
for (i = 0; i != NUM_CARGO; i++, mask >>= 1) {
+ if (b >= lastof(_userstring) - 5) break;
if (accepts[i] >= 8 && mask & 1) {
+ if (first) {
+ first = false;
+ } else {
+ /* Add a comma if this is not the first item */
+ *b++ = ',';
+ *b++ = ' ';
+ }
b = InlineString(b, _cargoc.names_s[i]);
- *b++ = ',';
- *b++ = ' ';
}
}
- if (b == &_userstring[3]) {
- b = InlineString(b, STR_00D0_NOTHING);
- *b++ = '\0';
- } else {
- b[-2] = '\0';
- }
+ /* If first is still true then no cargo is accepted */
+ if (first) b = InlineString(b, STR_00D0_NOTHING);
+ *b = '\0';
DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
}