Skip to content

Commit 18dbc68

Browse files
GongHeng2017manisandro
authored andcommitted
fix: Add null pointer check logic for pointer variables.
1. Some array variable can be declared as const array. 2. Add null pointer check logic for pointer variables.
1 parent 615ac1b commit 18dbc68

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

qt/src/Acquirer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ void Acquirer::startScan() {
135135
ui.pushButtonScanCancel->setVisible(true);
136136
ui.labelScanMessage->setText(_("Starting scan..."));
137137

138-
double dpi[] = {75.0, 100.0, 200.0, 300.0, 600.0, 1200.0};
139-
Scanner::ScanMode modes[] = {Scanner::ScanMode::GRAY, Scanner::ScanMode::COLOR};
140-
Scanner::ScanType types[] = {Scanner::ScanType::SINGLE, Scanner::ScanType::ADF_FRONT, Scanner::ScanType::ADF_BACK, Scanner::ScanType::ADF_BOTH};
138+
const double dpi[] = {75.0, 100.0, 200.0, 300.0, 600.0, 1200.0};
139+
const Scanner::ScanMode modes[] = {Scanner::ScanMode::GRAY, Scanner::ScanMode::COLOR};
140+
const Scanner::ScanType types[] = {Scanner::ScanType::SINGLE, Scanner::ScanType::ADF_FRONT, Scanner::ScanType::ADF_BACK, Scanner::ScanType::ADF_BOTH};
141141
genOutputPath();
142142
QString device = ui.comboBoxScanDevice->itemData(ui.comboBoxScanDevice->currentIndex()).toString();
143143
Scanner::Params params = {device, m_outputPath, dpi[ui.comboBoxScanResolution->currentIndex()], modes[ui.comboBoxScanMode->currentIndex()], 8, types[ui.comboBoxScanSource->currentIndex()], 0, 0};

qt/src/Displayer.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ bool Displayer::renderImage() {
281281
return false;
282282
}
283283
QImage image = renderer->render(m_currentSource->page, m_currentSource->resolution);
284-
if (image.isNull()) {
284+
if (image.isNull() || !m_imageItem) {
285285
return false;
286286
}
287287
renderer->adjustImage(image, m_currentSource->brightness, m_currentSource->contrast, m_currentSource->invert);
@@ -536,6 +536,8 @@ void Displayer::wheelEvent(QWheelEvent* event) {
536536

537537
QPointF Displayer::mapToSceneClamped(const QPoint& p) const {
538538
QPointF q = mapToScene(p);
539+
if (!m_imageItem)
540+
return q;
539541
QRectF bb = m_imageItem->sceneBoundingRect();
540542
q.rx() = std::min(std::max(bb.x(), q.x()), bb.x() + bb.width());
541543
q.ry() = std::min(std::max(bb.y(), q.y()), bb.y() + bb.height());

0 commit comments

Comments
 (0)