mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Remove broken and unused StrMakeValidInPlace overload. (#13960)
If an otherwise valid string without NUL termination was passed, a NUL was appended out of bounds.pull/13861/merge
parent
1befa1ccb0
commit
44984f8410
|
@ -82,12 +82,6 @@
|
||||||
# define CDECL
|
# define CDECL
|
||||||
#endif /* __GNUC__ || __clang__ */
|
#endif /* __GNUC__ || __clang__ */
|
||||||
|
|
||||||
#if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)
|
|
||||||
# define NOACCESS(args) __attribute__ ((access (none, args)))
|
|
||||||
#else
|
|
||||||
# define NOACCESS(args)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -188,30 +188,17 @@ static void StrMakeValid(T &dst, const char *str, const char *last, StringValida
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans the string for invalid characters and replaces then with a
|
* Scans the string for invalid characters and replaces them with a
|
||||||
* question mark '?' (if not ignored).
|
* question mark '?' (if not ignored).
|
||||||
* @param str The string to validate.
|
* @param str The string to validate.
|
||||||
* @param last The last valid character of str.
|
|
||||||
* @param settings The settings for the string validation.
|
* @param settings The settings for the string validation.
|
||||||
*/
|
* @note The string must be properly NUL terminated.
|
||||||
void StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings)
|
|
||||||
{
|
|
||||||
char *dst = str;
|
|
||||||
StrMakeValid(dst, str, last, settings);
|
|
||||||
*dst = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scans the string for invalid characters and replaces then with a
|
|
||||||
* question mark '?' (if not ignored).
|
|
||||||
* Only use this function when you are sure the string ends with a '\0';
|
|
||||||
* otherwise use StrMakeValidInPlace(str, last, settings) variant.
|
|
||||||
* @param str The string (of which you are sure ends with '\0') to validate.
|
|
||||||
*/
|
*/
|
||||||
void StrMakeValidInPlace(char *str, StringValidationSettings settings)
|
void StrMakeValidInPlace(char *str, StringValidationSettings settings)
|
||||||
{
|
{
|
||||||
/* We know it is '\0' terminated. */
|
char *dst = str;
|
||||||
StrMakeValidInPlace(str, str + strlen(str), settings);
|
StrMakeValid(dst, str, str + strlen(str), settings);
|
||||||
|
*dst = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,6 @@ void strecpy(std::span<char> dst, std::string_view src);
|
||||||
|
|
||||||
std::string FormatArrayAsHex(std::span<const uint8_t> data);
|
std::string FormatArrayAsHex(std::span<const uint8_t> data);
|
||||||
|
|
||||||
void StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK) NOACCESS(2);
|
|
||||||
[[nodiscard]] std::string StrMakeValid(std::string_view str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
[[nodiscard]] std::string StrMakeValid(std::string_view str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
||||||
void StrMakeValidInPlace(char *str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
void StrMakeValidInPlace(char *str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue