mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix assumption in gnc_num_dbg_to_string()
If the size of "buff" is not evenly divisible by "size" then this would allocate off the end of the buffer. That's not currently the case but the calculation shouldn't do this. Change it to check there's actually enough space.
This commit is contained in:
@@ -1290,12 +1290,12 @@ gnc_num_dbg_to_string(gnc_numeric n)
|
||||
{
|
||||
static char buff[1000];
|
||||
static char *p = buff;
|
||||
static const uint64_t size = 50;
|
||||
static const size_t size = 50;
|
||||
int64_t tmpnum = n.num;
|
||||
int64_t tmpdenom = n.denom;
|
||||
|
||||
p += size;
|
||||
if (p - buff >= 1000) p = buff;
|
||||
if ((size_t)(p - buff) > sizeof(buff) - size) p = buff;
|
||||
|
||||
snprintf(p, size, "%" PRId64 "/%" PRId64, tmpnum, tmpdenom);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user