diff options
| author | Zuhaitz <zuhaitz.zechhub@gmail.com> | 2026-01-25 22:36:29 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-25 22:36:29 +0000 |
| commit | dc69e7a19e86373ee117d56b3747ff56d1631e96 (patch) | |
| tree | 1b94f1f43b98a26a9c153585568505bed95e60ec /src/parser/parser_stmt.c | |
| parent | fa858115f6b9625065b2488aeee028fe2c7d60b2 (diff) | |
| parent | 74a4469dfba9a63a57caabc65c4faa65b2a59308 (diff) | |
Merge pull request #127 from sureshkrishnan-ai/JsonType
fixed buffer overflow in vector. Added serialize and deserialize in j…
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 9782a26..21d36eb 100644 --- a/src/parser/parser_stmt.c +++ b/src/parser/parser_stmt.c @@ -1595,10 +1595,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"; } @@ -1661,7 +1666,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 @@ -1671,9 +1685,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, ")); "); } } |
