ansilove

ANSI and ASCII art to PNG converter in C
Log | Files | Refs | README | LICENSE

commit 0966e1b17d00de145b76b7192e7c74e8d1448c1b
parent 9acbf3b00da6c6cbc3351a7b811442417d554830
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 18 Oct 2018 09:53:28 +0200

Check asprintf() return value and error if allocation fails

Diffstat:
Msrc/main.c | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -230,13 +230,19 @@ int main(int argc, char *argv[]) { // create output file name if output is not specified if (!output) { // appending ".png" extension to output file name - asprintf(&fileName, "%s%s", input, ".png"); + if (asprintf(&fileName, "%s%s", input, ".png") == -1) { + fprintf(stderr, "Memory allocation error.\n\n"); + return EXIT_FAILURE; + } } else { fileName = output; } if (options.retinaScaleFactor) { - asprintf(&retina, "%s@%ix.png", fileName, options.retinaScaleFactor); + if (asprintf(&retina, "%s@%ix.png", fileName, options.retinaScaleFactor) == -1) { + fprintf(stderr, "Memory allocation error.\n\n"); + return EXIT_FAILURE; + } } // default to empty string if mode option is not specified