mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
Reworked _dvsprintf a bit to make it cleaner and fix a segfault when
appending to large strings.
This commit is contained in:
parent
19ac57dafc
commit
2c643cde47
1 changed files with 9 additions and 16 deletions
|
@ -194,33 +194,26 @@ dstring_clearstr (dstring_t *dstr)
|
||||||
static int
|
static int
|
||||||
_dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args)
|
_dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
int size;
|
int size, rsize;
|
||||||
|
|
||||||
#ifdef VA_LIST_IS_ARRAY
|
#ifdef VA_LIST_IS_ARRAY
|
||||||
va_list tmp_args;
|
va_list tmp_args;
|
||||||
VA_COPY (tmp_args, args);
|
VA_COPY (tmp_args, args);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!dstr->truesize) {
|
if (!dstr->truesize)
|
||||||
dstr->size = 1024;
|
dstring_clearstr (dstr); // Make it a string
|
||||||
dstring_adjust (dstr);
|
// +1 for null
|
||||||
}
|
rsize = (size = vsnprintf (dstr->str + offs, dstr->truesize - offs, fmt, args)) + offs + 1;
|
||||||
// +1 for nul
|
dstr->size = rsize;
|
||||||
size = vsnprintf (dstr->str + offs, dstr->truesize - offs, fmt, args) + 1;
|
if (rsize > dstr->truesize) {
|
||||||
while (size <= 0 || size > dstr->truesize) {
|
|
||||||
if (size > 0)
|
|
||||||
dstr->size = (size + offs + 1023) & ~1023; // 1k multiples
|
|
||||||
else
|
|
||||||
dstr->size = dstr->truesize + 1024;
|
|
||||||
dstring_adjust (dstr);
|
dstring_adjust (dstr);
|
||||||
#ifdef VA_LIST_IS_ARRAY
|
#ifdef VA_LIST_IS_ARRAY
|
||||||
VA_COPY (args, tmp_args);
|
VA_COPY (args, tmp_args);
|
||||||
#endif
|
#endif
|
||||||
size = vsnprintf (dstr->str + offs, dstr->truesize - offs,
|
vsnprintf (dstr->str + offs, dstr->size - offs, fmt, args);
|
||||||
fmt, args) + 1;
|
|
||||||
}
|
}
|
||||||
dstr->size = size + offs;
|
return size;
|
||||||
return size - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in a new issue