diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-12 23:55:44 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-12 23:55:44 +0000 |
| commit | 4a427b6acf8fcc7ee8d1318faabf147d29d3a866 (patch) | |
| tree | 623f2047aa10134e9044fb899807a51edcb43f4d | |
| parent | 291650f52893682bfdb00a359461b6e4d5907a17 (diff) | |
Added hash seed randomizer and fixed truncation bug int variables
| -rw-r--r-- | src/ast/ast.h | 2 | ||||
| -rw-r--r-- | src/codegen/codegen.c | 2 | ||||
| -rw-r--r-- | src/parser/parser_expr.c | 14 | ||||
| -rw-r--r-- | std/core.zc | 2 | ||||
| -rw-r--r-- | std/map.zc | 3 | ||||
| -rw-r--r-- | std/set.zc | 3 | ||||
| -rw-r--r-- | std/time.zc | 9 |
7 files changed, 21 insertions, 14 deletions
diff --git a/src/ast/ast.h b/src/ast/ast.h index e22b35c..8c5bff4 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -311,7 +311,7 @@ struct ASTNode struct { int type_kind; - int int_val; + unsigned long long int_val; double float_val; char *string_val; } literal; diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index 17b0816..eef1057 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -494,7 +494,7 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out) else { - fprintf(out, "%d", node->literal.int_val); + fprintf(out, "%lluULL", (unsigned long long)node->literal.int_val); } break; case NODE_EXPR_CALL: diff --git a/src/parser/parser_expr.c b/src/parser/parser_expr.c index 93a50e2..f7af80f 100644 --- a/src/parser/parser_expr.c +++ b/src/parser/parser_expr.c @@ -918,22 +918,16 @@ ASTNode *parse_primary(ParserContext *ctx, Lexer *l) node->literal.type_kind = 0; node->type_info = type_new(TYPE_INT); char *s = token_strdup(t); - long long val; + unsigned long long val; if (t.len > 2 && s[0] == '0' && s[1] == 'b') { - val = strtoll(s + 2, NULL, 2); + val = strtoull(s + 2, NULL, 2); } else { - val = strtoll(s, NULL, 0); + val = strtoull(s, NULL, 0); } - - if (val > 2147483647LL || val < -2147483648LL) - { - warn_integer_overflow(t, "int", val); - } - - node->literal.int_val = (int)val; + node->literal.int_val = (unsigned long long)val; free(s); } else if (t.type == TOK_FLOAT) diff --git a/std/core.zc b/std/core.zc index daf6a96..bfa82ea 100644 --- a/std/core.zc +++ b/std/core.zc @@ -4,3 +4,5 @@ include <string.h> include <stdio.h> include <stdbool.h> include <stdarg.h> + +var __zen_hash_seed: usize = 14695981039346656037;
\ No newline at end of file @@ -3,8 +3,9 @@ import "./core.zc" import "./option.zc" raw { + extern size_t __zen_hash_seed; size_t _map_hash_str(const char* str) { - size_t hash = 14695981039346656037UL; + size_t hash = __zen_hash_seed; while (*str) { hash ^= (unsigned char)*str++; hash *= 1099511628211UL; @@ -3,8 +3,9 @@ import "./core.zc" import "./option.zc" raw { + extern size_t __zen_hash_seed; size_t _set_hash(const void* data, size_t len) { - size_t hash = 14695981039346656037UL; + size_t hash = __zen_hash_seed; const unsigned char* bytes = (const unsigned char*)data; for (size_t i = 0; i < len; i++) { hash ^= bytes[i]; diff --git a/std/time.zc b/std/time.zc index 72e611a..1191821 100644 --- a/std/time.zc +++ b/std/time.zc @@ -29,7 +29,16 @@ impl Duration { struct Time {} +extern size_t __zen_hash_seed; + impl Time { + fn randomize_hash() { + raw { + srand(time(NULL)); + __zen_hash_seed ^= (size_t)rand(); + } + } + fn now() -> U64 { return _time_now_impl(); } |
