Commit d65940ee authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Fix NULL pointer crash in ScanParams::slotNewResolution()

Happens when looking up the current scan resolution if the
SANE_NAME_SCAN_RESOLUTION and SANE_NAME_SCAN_X_RESOLUTION option
names are not the same and the scanner only has the former.  They were
equivalent in SANE 1.0.19, but in 1.0.20 they are different.

BUG:264768
parent 9637cf61
......@@ -817,15 +817,17 @@ KScanDevice::Status KScanDevice::acquirePreview( bool forceGray, int dpi )
}
/* Some sort of Scan Resolution option should always exist */
KScanOption res(SANE_NAME_SCAN_RESOLUTION);
kDebug() << "Scan resolution (before preview) is" << QString(res.get());
mSavedOptions->backupOption(res);
KScanOption *xres = getExistingGuiElement(SANE_NAME_SCAN_X_RESOLUTION);
if (xres==NULL) xres = getExistingGuiElement(SANE_NAME_SCAN_RESOLUTION);
kDebug() << "Scan resolution (before preview) is" << QString(xres->get());
mSavedOptions->backupOption(*xres);
int preview_dpi = dpi;
if (dpi==0) // preview DPI not specified
{
double min, max;
if (!res.getRange(&min, &max))
if (!xres->getRange(&min, &max))
{
kDebug() << "Could not retrieve resolution range!";
min = 75.0; // hope every scanner can do this
......@@ -837,15 +839,15 @@ KScanDevice::Status KScanDevice::acquirePreview( bool forceGray, int dpi )
}
/* Set scan resolution for preview */
if (!optionExists(SANE_NAME_SCAN_Y_RESOLUTION)) mCurrScanResolutionY = 0;
KScanOption *yres = getExistingGuiElement(SANE_NAME_SCAN_Y_RESOLUTION);
if (yres==NULL) mCurrScanResolutionY = 0;
else
{
KScanOption yres(SANE_NAME_SCAN_Y_RESOLUTION);
/* if active ? */
mSavedOptions->backupOption(yres);
yres.set(preview_dpi);
apply(&yres);
yres.get(&mCurrScanResolutionY);
mSavedOptions->backupOption(*yres);
yres->set(preview_dpi);
apply(yres);
yres->get(&mCurrScanResolutionY);
/* Resolution bind switch? */
if (optionExists(SANE_NAME_RESOLUTION_BIND))
......@@ -858,11 +860,11 @@ KScanDevice::Status KScanDevice::acquirePreview( bool forceGray, int dpi )
}
}
res.set(preview_dpi);
apply(&res);
xres->set(preview_dpi);
apply(xres);
/* Store the resulting preview for additional image information */
res.get(&mCurrScanResolutionX);
xres->get(&mCurrScanResolutionX);
if (mCurrScanResolutionY==0) mCurrScanResolutionY = mCurrScanResolutionX;
return (acquireData(true)); // perform the preview
......
......@@ -335,8 +335,10 @@ QWidget *ScanParams::createScannerParams()
frame->addRow(l, cb);
}
// Resolution setting. Try "X-Resolution" setting first, this is
// normally the same option as "Resolution" (according to saneopts.h).
// Resolution setting. Try "X-Resolution" setting first, this is the
// option we want if the resolutions are split up. If there is no such
// option then try just "Resolution", this may not be the same as
// "X-Resolution" even though this was the case in SANE<=1.0.19.
so = mSaneDevice->getGuiElement(SANE_NAME_SCAN_X_RESOLUTION, frame);
if (so==NULL) so = mSaneDevice->getGuiElement(SANE_NAME_SCAN_RESOLUTION, frame);
if (so!=NULL)
......@@ -1048,25 +1050,23 @@ void ScanParams::setMaximalScanSize()
void ScanParams::slotNewResolution(KScanOption *opt)
{
if (opt==NULL) return;
KScanOption *opt_x = mSaneDevice->getExistingGuiElement(SANE_NAME_SCAN_X_RESOLUTION);
if (opt_x==NULL) opt_x = mSaneDevice->getExistingGuiElement(SANE_NAME_SCAN_RESOLUTION);
KScanOption *opt_y = mSaneDevice->getExistingGuiElement(SANE_NAME_SCAN_Y_RESOLUTION);
int x_res = 0;
opt_x->get(&x_res); // get the X resolution
int x_res = 0; // get the X resolution
if (opt_x!=NULL && opt_x->isValid()) opt_x->get(&x_res);
int y_res = x_res; // assume Y same as X
int y_res = 0; // get the Y resolution
if (opt_y!=NULL && opt_y->isValid()) opt_y->get(&y_res);
if (opt_y!=NULL && opt_y->isValid()) // have separate X/Y settings
{
if (mResolutionBind!=NULL && mResolutionBind->isActive())
{ // settings may be different
opt_y->get(&y_res); // so read Y setting too
}
}
kDebug() << "X/Y resolution" << x_res << y_res;
if (y_res==0) y_res = x_res; // use X res if Y unavailable
if (x_res==0) x_res = y_res; // unlikely, but orthogonal
emit scanResolutionChanged(x_res, y_res);
if (x_res==0 && y_res==0) kDebug() << "resolution not available!";
else emit scanResolutionChanged(x_res, y_res);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment