From 3f8b67f6310adb2941e4e61284cb0b808795b39c Mon Sep 17 00:00:00 2001 From: JaiLuthra1 Date: Thu, 30 Jan 2020 18:05:15 +0530 Subject: [PATCH] rastertoescpx: added handling of empty input --- filter/rastertoescpx.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/filter/rastertoescpx.c b/filter/rastertoescpx.c index 79d310c3c..217f63c44 100644 --- a/filter/rastertoescpx.c +++ b/filter/rastertoescpx.c @@ -1747,6 +1747,7 @@ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { int fd; /* File descriptor */ + int empty = 1; cups_raster_t *ras; /* Raster stream for printing */ cups_page_header2_t header; /* Page header from file */ int page; /* Current page */ @@ -1837,12 +1838,6 @@ main(int argc, /* I - Number of command-line arguments */ signal(SIGTERM, CancelJob); #endif /* HAVE_SIGSET */ - /* - * Initialize the print device... - */ - - Setup(ppd); - /* * Process pages as needed... */ @@ -1855,6 +1850,15 @@ main(int argc, /* I - Number of command-line arguments */ * Write a status message with the page number and number of copies. */ + if (empty) + { + /* + * Initialize the print device... + */ + Setup(ppd); + empty = 0; + } + if (Canceled) break; @@ -1901,7 +1905,8 @@ main(int argc, /* I - Number of command-line arguments */ break; } - Shutdown(ppd); + if (!empty) + Shutdown(ppd); cupsFreeOptions(num_options, options); @@ -1914,6 +1919,11 @@ main(int argc, /* I - Number of command-line arguments */ if (DotBuffers[i] != NULL) free(DotBuffers[i]); + if (empty) + { + fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n"); + return 0; + } return (page == 0); } -- 2.47.2