From b9186ce83d0a55d04e5bc71a22e544238fc7d909 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Thu, 24 May 2018 13:44:09 +0200 Subject: [PATCH] Make argument const --- src/openrct2/localisation/Localisation.cpp | 14 ++++++++------ src/openrct2/localisation/Localisation.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index 5132eb7b2a..8fd9e1ef1a 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -1228,10 +1228,12 @@ void format_string_to_upper(utf8 *dest, size_t size, rct_string_id format, void dest[upperString.size()] = '\0'; } -money32 string_to_money(char * string_to_monetise) +money32 string_to_money(const char* string_to_monetise) { + char processedString[128]; + safe_strcpy(processedString, string_to_monetise, 128); const char* decimal_char = language_get_string(STR_LOCALE_DECIMAL_POINT); - char * text_ptr = string_to_monetise; + char* text_ptr = processedString; uint32 numNumbers = 0; bool hasMinus = false; bool hasDecSep = false; @@ -1292,13 +1294,13 @@ money32 string_to_money(char * string_to_monetise) // Due to the nature of strstr and strtok, decimals at the very beginning will be ignored, causing // ".1" to be interpreted as "1". To prevent this, prefix with "0" if decimal is at the beginning. - char * buffer = (char *)malloc(strlen(string_to_monetise) + 4); - if (string_to_monetise[0] == decimal_char[0]) { + char * buffer = (char *)malloc(strlen(processedString) + 4); + if (processedString[0] == decimal_char[0]) { strcpy(buffer, "0"); - strcpy(buffer + 1, string_to_monetise); + strcpy(buffer + 1, processedString); } else { - strcpy(buffer, string_to_monetise); + strcpy(buffer, processedString); } int number = 0, decimal = 0; diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index b3208a83c3..c3b9d93d14 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -42,7 +42,7 @@ sint32 get_string_length(const utf8 *text); // The maximum number of characters allowed for string/money conversions (anything above will risk integer overflow issues) #define MONEY_STRING_MAXLENGTH 14 -money32 string_to_money(char * string_to_monetise); +money32 string_to_money(const char* string_to_monetise); void money_to_string(money32 amount, char * buffer_to_put_value_to, size_t buffer_len); void user_string_clear_all();