From: Soeren Apel Date: Thu, 8 Mar 2018 23:28:42 +0000 (+0100) Subject: Fix #1125 by adding a missing typecast X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=20df1a39d587c284f5ee8873dc05470d6a6b11eb;p=pulseview.git Fix #1125 by adding a missing typecast Without this typecast, the return type of get_sample_count() is a uint64_t, which doesn't go well when it's 0 and we subtract 1 from it. Assigning the result of this underflow to an int64_t doesn't help, it's too late. --- diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index bbc23fb7..11a73068 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -285,7 +285,7 @@ void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp) const double pixels_offset = pp.pixels_offset(); const double samplerate = max(1.0, segment->samplerate()); const pv::util::Timestamp& start_time = segment->start_time(); - const int64_t last_sample = segment->get_sample_count() - 1; + const int64_t last_sample = (int64_t)segment->get_sample_count() - 1; const double samples_per_pixel = samplerate * pp.scale(); const pv::util::Timestamp start = samplerate * (pp.offset() - start_time); const pv::util::Timestamp end = start + samples_per_pixel * pp.width(); @@ -552,7 +552,7 @@ void AnalogSignal::paint_logic_mid(QPainter &p, ViewItemPaintParams &pp) const double pixels_offset = pp.pixels_offset(); const pv::util::Timestamp& start_time = segment->start_time(); - const int64_t last_sample = segment->get_sample_count() - 1; + const int64_t last_sample = (int64_t)segment->get_sample_count() - 1; const double samples_per_pixel = samplerate * pp.scale(); const double pixels_per_sample = 1 / samples_per_pixel; const pv::util::Timestamp start = samplerate * (pp.offset() - start_time); diff --git a/pv/views/trace/logicsignal.cpp b/pv/views/trace/logicsignal.cpp index 99900941..1f25890d 100644 --- a/pv/views/trace/logicsignal.cpp +++ b/pv/views/trace/logicsignal.cpp @@ -204,7 +204,7 @@ void LogicSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp) const double pixels_offset = pp.pixels_offset(); const pv::util::Timestamp& start_time = segment->start_time(); - const int64_t last_sample = segment->get_sample_count() - 1; + const int64_t last_sample = (int64_t)segment->get_sample_count() - 1; const double samples_per_pixel = samplerate * pp.scale(); const double pixels_per_sample = 1 / samples_per_pixel; const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);