From 899899533c4b71960c96aa8bdf6ec24513446ec6 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 19 Nov 2020 07:50:28 +0000 Subject: [PATCH] PacketListRecord: add an ensureColorized() method and use it. Don't call the columnString() and discard the result in order to force colorization; instead, add a separate method to force colorization and use that. This avoids the need to choose a column; we were using 1 as the column number, but column numbers are zero-origin, so that's column 2, which isn't guaranteed to exist (a crash ensued if it didn't). (cherry picked from commit 58aea1de62b9499d7b767f4aa631394f9fbb889e) --- ui/qt/models/packet_list_model.cpp | 2 +- ui/qt/models/packet_list_record.cpp | 25 +++++++++++++++++++++++++ ui/qt/models/packet_list_record.h | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ui/qt/models/packet_list_model.cpp b/ui/qt/models/packet_list_model.cpp index 50d929d569..2d62689ee0 100644 --- a/ui/qt/models/packet_list_model.cpp +++ b/ui/qt/models/packet_list_model.cpp @@ -760,7 +760,7 @@ void PacketListModel::ensureRowColorized(int row) if (!record) return; if (!record->colorized()) { - record->columnString(cap_file_, 1, true); + record->ensureColorized(cap_file_); } } diff --git a/ui/qt/models/packet_list_record.cpp b/ui/qt/models/packet_list_record.cpp index c5bc05b741..9be07c1035 100644 --- a/ui/qt/models/packet_list_record.cpp +++ b/ui/qt/models/packet_list_record.cpp @@ -46,6 +46,26 @@ PacketListRecord::~PacketListRecord() col_text_.clear(); } +void PacketListRecord::ensureColorized(capture_file *cap_file) +{ + // packet_list_store.c:packet_list_get_value + Q_ASSERT(fdata_); + + if (!cap_file) { + return; + } + + // + // XXX - do we need to check whether the data versions match? + // If the record's color is already correct, we shouldn't need + // to redissect it to colorize it. + // + bool dissect_color = !colorized_ || ( color_ver_ != rows_color_ver_ ); + if (data_ver_ != col_data_ver_ || dissect_color) { + dissect(cap_file, dissect_color); + } +} + // We might want to return a const char * instead. This would keep us from // creating excessive QByteArrays, e.g. in PacketListModel::recordLessThan. const QString PacketListRecord::columnString(capture_file *cap_file, int column, bool colorized) @@ -57,6 +77,11 @@ const QString PacketListRecord::columnString(capture_file *cap_file, int column, return QString(); } + // + // XXX - do we still need to check the colorization, given that we now + // have the ensureColorized() method to ensure that the record is + // properly colorized? + // bool dissect_color = ( colorized && !colorized_ ) || ( color_ver_ != rows_color_ver_ ); if (column >= col_text_.count() || col_text_.at(column).isNull() || data_ver_ != col_data_ver_ || dissect_color) { dissect(cap_file, dissect_color); diff --git a/ui/qt/models/packet_list_record.h b/ui/qt/models/packet_list_record.h index c649f3f96c..62d15e80b2 100644 --- a/ui/qt/models/packet_list_record.h +++ b/ui/qt/models/packet_list_record.h @@ -32,6 +32,8 @@ public: PacketListRecord(frame_data *frameData); virtual ~PacketListRecord(); + // Ensure that the record is colorized. + void ensureColorized(capture_file *cap_file); // Return the string value for a column. Data is cached if possible. const QString columnString(capture_file *cap_file, int column, bool colorized = false); frame_data *frameData() const { return fdata_; }