mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-29 20:20:43 +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... */
|
/* These may be underscored... */
|
||||||
#if defined(HAVE__SNPRINTF)
|
#if defined(HAVE__SNPRINTF)
|
||||||
# undef snprintf
|
# undef snprintf
|
||||||
# define snprintf _snprintf
|
# define snprintf Q_snprintfz
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE__VSNPRINTF)
|
#if defined(HAVE__VSNPRINTF)
|
||||||
# undef vsnprintf
|
# undef vsnprintf
|
||||||
# define vsnprintf _vsnprintf
|
# define vsnprintf Q_vsnprintfz
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32) && !defined(__BORLANDC__)
|
#if defined(_WIN32) && !defined(__BORLANDC__)
|
||||||
# define kbhit _kbhit
|
# define kbhit _kbhit
|
||||||
|
|
|
@ -65,3 +65,29 @@ Q_strnlen (const char *s, size_t maxlen)
|
||||||
for (i = 0; i < maxlen && s[i]; i++);
|
for (i = 0; i < maxlen && s[i]; i++);
|
||||||
return 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