From a79edcfebaf9a96420ea00757ea76d14c1aa06cf Mon Sep 17 00:00:00 2001 From: Armaan Sandhu Date: Sun, 1 Nov 2026 19:10:33 -0500 Subject: [PATCH] ppd-generator: drop the broken URF default resolution check the loop compared current_def to a newly allocated resolution, so it compared pointers and never matched, and it used the outer loop index. the result was always the middle resolution, and it leaked memory on every pass. the middle resolution is the right default anyway, since printer-resolution-default is about the print engine and not the raster data. so just use it and remove the loop. no change to the generated PPD. --- ppd/ppd-generator.c | 22 +++++----------------- ppd/test_ppd_generator.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ppd/ppd-generator.c b/ppd/ppd-generator.c index 4de0a536..081e84aa 100644 --- a/ppd/ppd-generator.c +++ b/ppd/ppd-generator.c @@ -949,10 +949,8 @@ ppdCreatePPDFromIPP2(char *buffer, // I - Filename buffer cfFreeResolution(current_def, NULL); } current_def = NULL; - // Checking if there is printer-default-resolution and this - // resolution is in the list, use it. If not, use the - // middpi, rounding down if the number of available - // resolutions is even. + // Use the middpi as the default, rounding down if the number + // of available resolutions is even. if ((attr = ippFindAttribute(supported, "printer-resolution-supported", IPP_TAG_RESOLUTION)) != NULL) @@ -961,19 +959,9 @@ ppdCreatePPDFromIPP2(char *buffer, // I - Filename buffer "printer-resolution-default", IPP_TAG_RESOLUTION)) != NULL) { - current_def = cfIPPResToResolution(defattr, 0); - for (int j = 0; j < resStore; j ++) - { - if (current_def == cfNewResolution(resArray[i], resArray[i])) - { - current_def = cfIPPResToResolution(defattr, 0); - break; - } - else - { - current_def = cfNewResolution(middpi, middpi); - } - } + // printer-resolution-default describes the print engine, not + // the raster data we send, so it isn't used as the default here + current_def = cfNewResolution(middpi, middpi); } } if (cupsArrayGetCount(current_res) > 0 && diff --git a/ppd/test_ppd_generator.c b/ppd/test_ppd_generator.c index da0ba9f8..6bd95885 100644 --- a/ppd/test_ppd_generator.c +++ b/ppd/test_ppd_generator.c @@ -902,6 +902,33 @@ main(void) free(ppd_text); ippDelete(resp); + // T32b — URF printer: printer-resolution-default is about the print engine, + // so the default for the raster data stays the middle resolution. +#ifdef CUPS_RASTER_HAVE_APPLERASTER + { + static const char * const urf[] = { "V1.4", "W8", "RS300-600-1200" }; + static const int dpi[] = { 300, 600, 1200 }; + + testBegin("URF printer-resolution-default 1200dpi → *DefaultResolution: 600dpi"); + resp = ippNew(); + add_format(resp, "image/urf"); + ippAddStrings(resp, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "urf-supported", + 3, NULL, urf); + ippAddResolutions(resp, IPP_TAG_PRINTER, "printer-resolution-supported", + 3, IPP_RES_PER_INCH, dpi, dpi); + ippAddResolution(resp, IPP_TAG_PRINTER, "printer-resolution-default", + IPP_RES_PER_INCH, 1200, 1200); + result = ppdCreatePPDFromIPP2(buffer, sizeof(buffer), resp, + "Test", "image/urf", + 0, 0, NULL, NULL, NULL, NULL, NULL, 0); + ppd_text = result ? slurp_file(buffer) : NULL; + testEnd(ppd_text && strstr(ppd_text, "*DefaultResolution: 600dpi")); + if (result == buffer) unlink(buffer); + free(ppd_text); + ippDelete(resp); + } +#endif // CUPS_RASTER_HAVE_APPLERASTER + // T33 — Asymmetric resolution 600x1200 → "*DefaultResolution: 600x1200dpi" // form at line 2413 (else branch). testBegin("printer-resolution-default 600x1200 → \"600x1200dpi\"");