From 0bb69cb67078dfa921b5b8a42275ef31dfbc9a56 Mon Sep 17 00:00:00 2001 From: suresh Date: Sun, 25 Jan 2026 11:24:22 -0500 Subject: fixed beffer overflow in vector. Added serialize and deserialize in json with vector reading from the struct with json --- src/parser/parser_stmt.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/parser/parser_stmt.c') 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, ")); "); } } -- cgit v1.2.3