core: Fix a possible buffer overrun

From bsekisser@github

Signed-off-by: Michel Pollet <buserror@gmail.com>