FFstrbuf: don't crash with ffStrbufAppendNC(&str, 0, 'c')

This commit is contained in:
李通洲 2023-12-11 14:00:50 +08:00
parent a28dc8a9bf
commit 165c213ed0
No known key found for this signature in database
GPG Key ID: 269AD4F5325A22A3
2 changed files with 8 additions and 3 deletions

View File

@ -5,6 +5,9 @@ Features:
* Support Apple M3X temperature detection (CPU / GPU, macOS)
* `--ds-force-drm` support a new option `sysfs-only`
Bugfixes:
* Fix crashes sometimes when `--logo-padding-top` is not set (Logo)
# 2.3.4
Bugfixes:

View File

@ -59,9 +59,9 @@ void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free)
uint32_t oldFree = ffStrbufGetFree(strbuf);
if (oldFree >= free && !(strbuf->allocated == 0 && strbuf->length > 0))
return;
uint32_t newCap = strbuf->allocated + (free - oldFree);
if(strbuf->allocated == 0)
{
newCap += strbuf->length + 1; // +1 for the NUL
@ -74,7 +74,7 @@ void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free)
}
else
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * newCap);
strbuf->allocated = newCap;
}
@ -99,6 +99,8 @@ void ffStrbufAppendC(FFstrbuf* strbuf, char c)
void ffStrbufAppendNC(FFstrbuf* strbuf, uint32_t num, char c)
{
if (num == 0) return;
ffStrbufEnsureFree(strbuf, num);
memset(&strbuf->chars[strbuf->length], c, num);
strbuf->length += num;