libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit 1142259bc23671d17a50f4fc366a18693fbe1744
parent ab09af31a71af76f068fd50055e8635856831e02
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 22 Nov 2018 13:36:32 +0100

Always check that seqTok is not NULL before using it (Fixes #4)

Diffstat:
Msrc/loaders/ansi.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -380,14 +380,15 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) seqGrab = strndup((char *)ctx->buffer + loop + 2, ansi_sequence_loop); seqTok = strtok(seqGrab, ";"); - seqValue = strtonum(seqTok, 0, UCHAR_MAX, &errstr); + if (seqTok) + seqValue = strtonum(seqTok, 0, UCHAR_MAX, &errstr); seqTok = strtok(NULL, ";"); - color_R = strtonum(seqTok, 0, UCHAR_MAX, &errstr) & 0xff; + color_R = seqTok ? strtonum(seqTok, 0, UCHAR_MAX, &errstr) & 0xff : 0; seqTok = strtok(NULL, ";"); - color_G = strtonum(seqTok, 0, UCHAR_MAX, &errstr) & 0xff; + color_G = seqTok ? strtonum(seqTok, 0, UCHAR_MAX, &errstr) & 0xff : 0; seqTok = strtok(NULL, ";"); - color_B = strtonum(seqTok, 0, UCHAR_MAX, &errstr) & 0xff; + color_B = seqTok ? strtonum(seqTok, 0, UCHAR_MAX, &errstr) & 0xff : 0; if (seqValue == 0) background = (color_R << 16) | (color_G << 8) | color_B;