fix: scf_lex_word_clone() lost copy data when some type
authoryu.dongliang <18588496441@163.com>
Sun, 29 Sep 2024 06:15:47 +0000 (14:15 +0800)
committeryu.dongliang <18588496441@163.com>
Sun, 29 Sep 2024 06:15:47 +0000 (14:15 +0800)
core/scf_lex_word.c
core/scf_lex_word.h
lex/scf_lex_util.c

index e320aef4a2f131d53db3455f00bf7c15dafaf49b..242bc829d98deab4ffb26351c19f3d89572beeab 100644 (file)
@@ -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;
        };
 
index 85ddb3ca193692f0f797d2f6465444673d72ed9b..d8ebde8774211d824447f1d81a46247db56e9a14 100644 (file)
@@ -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,
index 25a3aed3c445ab688d182400e97953f22ee5a589..67d765b567caac23e3f9162948b4dcd022097258 100644 (file)
@@ -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);
        }