mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
_snprintf and _vsnprintf are not guaranteed to write the trailing '\0'
This commit is contained in:
parent
522f64bce1
commit
3c6f64b26b
2 changed files with 28 additions and 2 deletions
|
@ -58,11 +58,11 @@
|
|||
/* These may be underscored... */
|
||||
#if defined(HAVE__SNPRINTF)
|
||||
# undef snprintf
|
||||
# define snprintf _snprintf
|
||||
# define snprintf Q_snprintfz
|
||||
#endif
|
||||
#if defined(HAVE__VSNPRINTF)
|
||||
# undef vsnprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# define vsnprintf Q_vsnprintfz
|
||||
#endif
|
||||
#if defined(_WIN32) && !defined(__BORLANDC__)
|
||||
# define kbhit _kbhit
|
||||
|
|
|
@ -65,3 +65,29 @@ Q_strnlen (const char *s, size_t maxlen)
|
|||
for (i = 0; i < maxlen && s[i]; i++);
|
||||
return i;
|
||||
}
|
||||
|
||||
#ifdef HAVE__VSNPRINTF
|
||||
void
|
||||
Q_snprintfz (char *dest, size_t size, char *fmt, ...)
|
||||
{
|
||||
int len;
|
||||
va_list argptr;
|
||||
|
||||
va_start (argptr, fmt);
|
||||
len = _vsnprintf (dest, size - 1, fmt, argptr);
|
||||
va_end (argptr);
|
||||
if (len < 0) // the string didn't fit into the buffer
|
||||
dest[size - 1] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Q_vsnprintfz (char *dest, size_t size, va_list argptr)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = _vsnprintf (dest, size - 1, fmt, argptr);
|
||||
|
||||
if (len < 0) // the string didn't fit into the buffer
|
||||
dest[size - 1] = 0;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue