From 20d602bf2eba4685a0b95674515993a38b062c79 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 29 Sep 2024 14:15:47 +0800 Subject: [PATCH] fix: scf_lex_word_clone() lost copy data when some type --- core/scf_lex_word.c | 35 +++++++++++++---------------------- core/scf_lex_word.h | 2 +- lex/scf_lex_util.c | 11 ++++++----- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/core/scf_lex_word.c b/core/scf_lex_word.c index e320aef..242bc82 100644 --- a/core/scf_lex_word.c +++ b/core/scf_lex_word.c @@ -32,40 +32,31 @@ scf_lex_word_t* scf_lex_word_clone(scf_lex_word_t* w) w1->type = w->type; - switch (w->type) { - case SCF_LEX_WORD_CONST_CHAR: - w1->data.u32 = w->data.u32; - break; - - case SCF_LEX_WORD_CONST_STRING: - - w1->data.s = scf_string_clone(w->data.s); - if (!w1->data.s) { - free(w1); - return NULL; - } - break; - - case SCF_LEX_WORD_CONST_INT: - w1->data.i = w->data.i; - break; + switch (w->type) + { case SCF_LEX_WORD_CONST_FLOAT: w1->data.f = w->data.f; break; + case SCF_LEX_WORD_CONST_DOUBLE: w1->data.d = w->data.d; break; + case SCF_LEX_WORD_CONST_COMPLEX: w1->data.z = w->data.z; break; - case SCF_LEX_WORD_CONST_I64: - w1->data.i64 = w->data.i64; - break; - case SCF_LEX_WORD_CONST_U64: - w1->data.u64 = w->data.u64; + case SCF_LEX_WORD_CONST_STRING: + + w1->data.s = scf_string_clone(w->data.s); + if (!w1->data.s) { + free(w1); + return NULL; + } break; + default: + w1->data.u64 = w->data.u64; break; }; diff --git a/core/scf_lex_word.h b/core/scf_lex_word.h index 85ddb3c..d8ebde8 100644 --- a/core/scf_lex_word.h +++ b/core/scf_lex_word.h @@ -159,11 +159,11 @@ enum scf_lex_words SCF_LEX_WORD_CONST_CHAR, SCF_LEX_WORD_CONST_STRING, - SCF_LEX_WORD_CONST_INT, SCF_LEX_WORD_CONST_FLOAT, SCF_LEX_WORD_CONST_DOUBLE, SCF_LEX_WORD_CONST_COMPLEX, + SCF_LEX_WORD_CONST_INT, SCF_LEX_WORD_CONST_U32, SCF_LEX_WORD_CONST_I64, SCF_LEX_WORD_CONST_U64, diff --git a/lex/scf_lex_util.c b/lex/scf_lex_util.c index 25a3aed..67d765b 100644 --- a/lex/scf_lex_util.c +++ b/lex/scf_lex_util.c @@ -550,7 +550,7 @@ int _lex_dot(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) return ret; } - if (scf_lex_is_const(w1)) { + if (SCF_LEX_WORD_CONST_INT <= w1->type && w1->type <= SCF_LEX_WORD_CONST_U64) { ret = __lex_pop_word(lex, &w2); if (ret < 0) { @@ -561,7 +561,7 @@ int _lex_dot(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) scf_lex_push_word(lex, w2); - if (w2->type != SCF_LEX_WORD_ASSIGN) { + if (w2->type != SCF_LEX_WORD_ASSIGN && w2->type != SCF_LEX_WORD_DOT) { w->type = SCF_LEX_WORD_CONST_DOUBLE; ret = scf_string_cat(w->text, w1->text); @@ -574,9 +574,10 @@ int _lex_dot(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) } w->data.d = atof(w->text->data); - } else - scf_lex_push_word(lex, w1); - } else + } + } + + if (w1) scf_lex_push_word(lex, w1); } -- 2.25.1