From: Soeren Apel Date: Thu, 12 Dec 2019 21:33:03 +0000 (+0100) Subject: Fix segfault and use bin class description X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cbf428c209788f1c0860cc7a1247a279379db303;p=pulseview.git Fix segfault and use bin class description --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index ad5a27a9..33861ea5 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -1426,7 +1426,7 @@ void DecodeSignal::binary_callback(srd_proto_data *pdata, void *decode_signal) DecodeBinaryClass* bin_class = nullptr; for (DecodeBinaryClass& bc : segment->binary_classes) - if ((bc.decoder->decoder() == decc) && (bc.info->bin_class_id == pdb->bin_class)) + if ((bc.decoder->decoder() == decc) && (bc.info->bin_class_id == (uint32_t)pdb->bin_class)) bin_class = &bc; if (!bin_class) { diff --git a/pv/views/decoder_output/QHexView.cpp b/pv/views/decoder_output/QHexView.cpp index 051e0b1f..2c99ba97 100644 --- a/pv/views/decoder_output/QHexView.cpp +++ b/pv/views/decoder_output/QHexView.cpp @@ -122,6 +122,7 @@ void QHexView::initialize_byte_iterator(size_t offset) { current_chunk_id_ = 0; current_chunk_offset_ = 0; + current_offset_ = offset; for (const DecodeBinaryDataChunk& chunk : data_->chunks) if (offset >= chunk.data.size()) { @@ -142,7 +143,9 @@ uint8_t QHexView::get_next_byte(bool* is_next_chunk) uint8_t v = current_chunk_->data[current_chunk_offset_]; + current_offset_++; current_chunk_offset_++; + if (current_chunk_offset_ == current_chunk_->data.size()) { current_chunk_id_++; current_chunk_offset_ = 0; @@ -237,7 +240,7 @@ void QHexView::paintEvent(QPaintEvent *event) for (size_t lineIdx = firstLineIdx, y = yStart; lineIdx < lastLineIdx; lineIdx++) { int x = posHex_; - for (size_t i = 0; i < BYTES_PER_LINE && ((lineIdx - firstLineIdx) * BYTES_PER_LINE + i) < data_size_; i++) { + for (size_t i = 0; (i < BYTES_PER_LINE) && (current_offset_ < data_size_); i++) { size_t pos = (lineIdx * BYTES_PER_LINE + i) * 2; // Fetch byte @@ -283,7 +286,7 @@ void QHexView::paintEvent(QPaintEvent *event) for (size_t lineIdx = firstLineIdx, y = yStart; lineIdx < lastLineIdx; lineIdx++) { int x = posAscii_; - for (size_t i = 0; ((lineIdx - firstLineIdx) * BYTES_PER_LINE + i) < data_size_ && (i < BYTES_PER_LINE); i++) { + for (size_t i = 0; (i < BYTES_PER_LINE) && (current_offset_ < data_size_); i++) { // Fetch byte uint8_t ch = get_next_byte(); diff --git a/pv/views/decoder_output/QHexView.hpp b/pv/views/decoder_output/QHexView.hpp index 74b9da56..fca3c7ef 100644 --- a/pv/views/decoder_output/QHexView.hpp +++ b/pv/views/decoder_output/QHexView.hpp @@ -84,7 +84,7 @@ private: size_t charWidth_, charHeight_; size_t selectBegin_, selectEnd_, selectInit_, cursorPos_; - size_t current_chunk_id_, current_chunk_offset_; + size_t current_chunk_id_, current_chunk_offset_, current_offset_; const DecodeBinaryDataChunk* current_chunk_; vector chunk_colors_; diff --git a/pv/views/decoder_output/view.cpp b/pv/views/decoder_output/view.cpp index d8bbb03a..2476d7ce 100644 --- a/pv/views/decoder_output/view.cpp +++ b/pv/views/decoder_output/view.cpp @@ -226,7 +226,7 @@ void View::on_selected_decoder_changed(int index) uint32_t bin_classes = decoder_->get_binary_class_count(); for (uint32_t i = 0; i < bin_classes; i++) { const data::decode::DecodeBinaryClassInfo* class_info = decoder_->get_binary_class(i); - class_selector_->addItem(class_info->name, QVariant::fromValue(i)); + class_selector_->addItem(class_info->description, QVariant::fromValue(i)); } connect(signal_, SIGNAL(new_binary_data(unsigned int, void*, unsigned int)),