From ae292619788bf7cdc33b669d1d3771294a60ccf1 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sat, 11 Apr 2015 15:29:37 +0000 Subject: [PATCH] Remove compiler warning and avoid a potential issue with IB Subtracting unsigned types is tricky, made sure result does not wrap to avoid potentially implementation defined behaviour. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5211 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- mainwindow.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 4beabefe5..b8508b949 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,7 +3,6 @@ #include "mainwindow.h" #include -#include #include #include @@ -953,8 +952,12 @@ void MainWindow::displayDialFrequency () bool valid {false}; for (int row = 0; row < frequencies->rowCount (); ++row) { + // we need to do specific checks for above and below here to + // ensure that we can use unsigned Radio::Frequency since we + // potentially use the full 64-bit unsigned range. auto working_frequency = frequencies->data (frequencies->index (row, 0)).value (); - if (std::llabs (working_frequency - m_dialFreq) < 10000) + auto offset = m_dialFreq > working_frequency ? m_dialFreq - working_frequency : working_frequency - m_dialFreq; + if (offset < 10000u) { valid = true; }