summaryrefslogtreecommitdiff
path: root/src/vehicle_cmd.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2010-03-21 11:35:41 +0000
committerpeter1138 <peter1138@openttd.org>2010-03-21 11:35:41 +0000
commite188c5d87c2092a7fd711493d6f7f045c0c9783b (patch)
treeb61281b79f54a3e492d0b3d2c8f013943eae49cf /src/vehicle_cmd.cpp
parentc049bf3f388438c9901981b1943b35fc3add3e4d (diff)
downloadopenttd-e188c5d87c2092a7fd711493d6f7f045c0c9783b.tar.xz
(svn r19498) -Feature [FS#3710]: Keep number padding intact when cloning vehicle names.
Diffstat (limited to 'src/vehicle_cmd.cpp')
-rw-r--r--src/vehicle_cmd.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 843f3625e..892d05c52 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -359,6 +359,7 @@ static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
/* Format buffer and determine starting number. */
int num;
+ byte padding = 0;
if (number_position == strlen(src->name)) {
/* No digit at the end, so start at number 2. */
strecpy(buf, src->name, lastof(buf));
@@ -369,13 +370,15 @@ static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
/* Found digits, parse them and start at the next number. */
strecpy(buf, src->name, lastof(buf));
buf[number_position] = '\0';
- num = strtol(&src->name[number_position], NULL, 10) + 1;
+ char *endptr;
+ num = strtol(&src->name[number_position], &endptr, 10) + 1;
+ padding = endptr - &src->name[number_position];
}
/* Check if this name is already taken. */
for (int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) {
/* Attach the number to the temporary name. */
- seprintf(&buf[number_position], lastof(buf), "%d", num);
+ seprintf(&buf[number_position], lastof(buf), "%0*d", padding, num);
/* Check the name is unique. */
if (IsUniqueVehicleName(buf)) {