diff options
| author | suresh <sureshkrishnan.ai@gmail.com> | 2026-01-25 11:24:22 -0500 |
|---|---|---|
| committer | suresh <sureshkrishnan.ai@gmail.com> | 2026-01-25 11:24:22 -0500 |
| commit | 0bb69cb67078dfa921b5b8a42275ef31dfbc9a56 (patch) | |
| tree | b579695576ae27f7316866b18bd54073f8e2ca1f /src/parser/parser_stmt.c | |
| parent | 0bd7b99fbf813415b9a0217eaa2a4e8f6f74e1ea (diff) | |
fixed beffer overflow in vector. Added serialize and deserialize in json with vector reading from the struct with json
Diffstat (limited to 'src/parser/parser_stmt.c')
| -rw-r--r-- | src/parser/parser_stmt.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c index 4b09c83..54e9b88 100644 --- a/src/parser/parser_stmt.c +++ b/src/parser/parser_stmt.c @@ -1591,10 +1591,15 @@ char *process_printf_sugar(ParserContext *ctx, const char *content, int newline, Type *t = expr_node ? expr_node->type_info : NULL; char *inferred_type = t ? type_to_string(t) : find_symbol_type(ctx, clean_expr); + int is_bool = 0; if (inferred_type) { - if (strcmp(inferred_type, "int") == 0 || strcmp(inferred_type, "i32") == 0 || - strcmp(inferred_type, "bool") == 0) + if (strcmp(inferred_type, "bool") == 0) + { + format_spec = "%s"; + is_bool = 1; + } + else if (strcmp(inferred_type, "int") == 0 || strcmp(inferred_type, "i32") == 0) { format_spec = "%d"; } @@ -1657,7 +1662,16 @@ char *process_printf_sugar(ParserContext *ctx, const char *content, int newline, strcat(gen, buf); strcat(gen, format_spec); strcat(gen, "\", "); - strcat(gen, rw_expr); + if (is_bool) + { + strcat(gen, "_z_bool_str("); + strcat(gen, rw_expr); + strcat(gen, ")"); + } + else + { + strcat(gen, rw_expr); + } strcat(gen, "); "); } else @@ -1667,9 +1681,9 @@ char *process_printf_sugar(ParserContext *ctx, const char *content, int newline, sprintf(buf, "fprintf(%s, _z_str(", target); strcat(gen, buf); strcat(gen, rw_expr); - strcat(gen, "), "); + strcat(gen, "), _z_arg("); strcat(gen, rw_expr); - strcat(gen, "); "); + strcat(gen, ")); "); } } |
