diff options
Diffstat (limited to 'indra/llcommon/llstring.cpp')
-rw-r--r-- | indra/llcommon/llstring.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 767a72dfe9..c6f436a5bb 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -654,6 +654,33 @@ std::string mbcsstring_makeASCII(const std::string& wstr) return out_str; } +#if LL_WINDOWS +/* If the size of the passed in buffer is not large enough to hold the string, + * two bad things happen: + * 1. resulting formatted string is NOT null terminated + * 2. Depending on the platform, the return value could be a) the required + * size of the buffer to copy the entire formatted string or b) -1. + * On Windows with VS.Net 2003, it returns -1 e.g. + * + * safe_snprintf always adds a NULL terminator so that the caller does not + * need to check for return value or need to add the NULL terminator. + * It does not, however change the return value - to let the caller know + * that the passed in buffer size was not large enough to hold the formatted string. + * + */ +int safe_snprintf(char *str, size_t size, const char *format, ...) +{ + va_list args; + va_start(args, format); + + int num_written = _vsnprintf(str, size, format, args); /* Flawfinder: ignore */ + va_end(args); + + str[size-1] = '\0'; // always null terminate + return num_written; +} +#endif // LL_WINDOWS + S32 LLStringOps::collate(const llwchar* a, const llwchar* b) { #if LL_WINDOWS |