diff -r 93ab363cc470 src/vehicle_cmd.cpp --- a/src/vehicle_cmd.cpp Fri Mar 19 21:00:15 2010 +0000 +++ b/src/vehicle_cmd.cpp Fri Mar 19 22:12:32 2010 +0100 @@ -354,6 +354,7 @@ /* 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)); @@ -364,13 +365,15 @@ /* 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)) {