From 2067d5973bc3f5603507d6d2e1bb209ce459e32b Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Mon, 15 May 2023 18:58:28 +0800 Subject: [PATCH] fix: The hex format string of decoder result, max length up to 256 --- DSView/pv/data/decode/annotation.cpp | 12 ++++++++++-- DSView/pv/data/decode/annotationrestable.cpp | 3 +++ DSView/pv/data/decode/annotationrestable.h | 6 +++--- DSView/pv/mainwindow.cpp | 6 ++---- lang/cn/msg.json | 2 +- libsigrokdecode4DSL/libsigrokdecode.h | 2 +- libsigrokdecode4DSL/type_decoder.c | 3 ++- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/DSView/pv/data/decode/annotation.cpp b/DSView/pv/data/decode/annotation.cpp index f26a8bb2..cf2ca6dc 100644 --- a/DSView/pv/data/decode/annotation.cpp +++ b/DSView/pv/data/decode/annotation.cpp @@ -87,8 +87,16 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status) //get numeric data if (pda->str_number_hex[0]){ - strcpy(resItem->str_number_hex, pda->str_number_hex); - resItem->is_numeric = true; + int str_len = strlen(pda->str_number_hex); + + if (str_len <= DECODER_MAX_DATA_BLOCK_LEN){ + resItem->str_number_hex = (char*)malloc(str_len + 1); + + if (resItem->str_number_hex != NULL){ + strcpy(resItem->str_number_hex, pda->str_number_hex); + resItem->is_numeric = true; + } + } } _status->m_bNumeric |= resItem->is_numeric; diff --git a/DSView/pv/data/decode/annotationrestable.cpp b/DSView/pv/data/decode/annotationrestable.cpp index ee382d70..c73edceb 100644 --- a/DSView/pv/data/decode/annotationrestable.cpp +++ b/DSView/pv/data/decode/annotationrestable.cpp @@ -117,6 +117,7 @@ int AnnotationResTable::MakeIndex(const std::string &key, AnnotationSourceItem* item->cur_display_format = -1; item->is_numeric = false; + item->str_number_hex = NULL; newItem = item; int dex = m_indexs.size(); @@ -331,6 +332,8 @@ void AnnotationResTable::reset() { //release all resource for (auto p : m_resourceTable){ + if (p->str_number_hex) + free(p->str_number_hex); delete p; } m_resourceTable.clear(); diff --git a/DSView/pv/data/decode/annotationrestable.h b/DSView/pv/data/decode/annotationrestable.h index 6fbe95ac..0151ca0b 100644 --- a/DSView/pv/data/decode/annotationrestable.h +++ b/DSView/pv/data/decode/annotationrestable.h @@ -26,14 +26,14 @@ #include #include -#define DECODER_MAX_DATA_BLOCK_LEN 35 +#define DECODER_MAX_DATA_BLOCK_LEN 256 #define CONVERT_STR_MAX_LEN 150 struct AnnotationSourceItem { bool is_numeric; - char str_number_hex[DECODER_MAX_DATA_BLOCK_LEN]; //numerical value hex format string - long long numberic_value; + char *str_number_hex; //numerical value hex format string + std::vector src_lines; //the origin source string lines std::vector cvt_lines; //the converted to bin/hex/oct format string lines int cur_display_format; //current format as bin/ex/oct..., init with -1 diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index d4320268..f818a92c 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -1704,13 +1704,11 @@ namespace pv _protocol_widget->update_view_status(); break; - case DSV_MSG_COLLECT_END: - dsv_info("Mainwindow:DSV_MSG_COLLECT_END"); + case DSV_MSG_COLLECT_END: prgRate(0); _view->repeat_unshow(); _view->on_state_changed(true); - _protocol_widget->update_view_status(); - dsv_info("Mainwindow-end:DSV_MSG_COLLECT_END"); + _protocol_widget->update_view_status(); break; case DSV_MSG_END_COLLECT_WORK: diff --git a/lang/cn/msg.json b/lang/cn/msg.json index 75ad9e7c..05cedb4e 100644 --- a/lang/cn/msg.json +++ b/lang/cn/msg.json @@ -369,6 +369,6 @@ }, { "id": "IDS_MSG_DEVICE_BUSY_SWITCH_FAILED", - "text": "设置在使用中,切换失败!" + "text": "设备在使用中,切换失败!" } ] \ No newline at end of file diff --git a/libsigrokdecode4DSL/libsigrokdecode.h b/libsigrokdecode4DSL/libsigrokdecode.h index cc0ad5d8..79f1d23a 100644 --- a/libsigrokdecode4DSL/libsigrokdecode.h +++ b/libsigrokdecode4DSL/libsigrokdecode.h @@ -26,7 +26,7 @@ #include #include -#define DECODE_NUM_HEX_MAX_LEN 35 +#define DECODE_NUM_HEX_MAX_LEN 256 #ifdef __cplusplus extern "C" { diff --git a/libsigrokdecode4DSL/type_decoder.c b/libsigrokdecode4DSL/type_decoder.c index 3b019e1e..dab18f73 100644 --- a/libsigrokdecode4DSL/type_decoder.c +++ b/libsigrokdecode4DSL/type_decoder.c @@ -132,6 +132,7 @@ static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size nstr = strlen(str) - 1; if (nstr > 0 && nstr < DECODE_NUM_HEX_MAX_LEN){ strcpy(hex_str_buf, str + 1); + str[0] = '\n'; //set ignore flag str[1] = 0; } @@ -241,7 +242,7 @@ static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj, pda->str_number_hex[0] = 0; ann_text = NULL; - pda->numberic_value = 0; + pda->numberic_value = 0; if (py_parse_ann_data(py_tmp, &ann_text, ann_size, pda->str_number_hex, &pda->numberic_value) != SRD_OK) { srd_err("Protocol decoder %s submitted annotation list, but "