diff options
author | Karen Clark <karen@lindenlab.com> | 2007-03-20 22:21:42 +0000 |
---|---|---|
committer | Karen Clark <karen@lindenlab.com> | 2007-03-20 22:21:42 +0000 |
commit | fceae96eb171be0396512e251aab311d4e3ef9cc (patch) | |
tree | e648d1dd42aeae4d47168bd8d696ff0895819b8b /indra/llcommon/llstring.cpp | |
parent | 5e9e67cb2d1d3dfc82dfe96103270b2341991ddd (diff) |
svn merge -r59459:59476 svn+ssh://svn.lindenlab.com/svn/linden/branches/adroit.r69-75_2 into svn+ssh://svn.lindenlab.com/svn/linden/release.
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 |