summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-12 23:55:44 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-12 23:55:44 +0000
commit4a427b6acf8fcc7ee8d1318faabf147d29d3a866 (patch)
tree623f2047aa10134e9044fb899807a51edcb43f4d /src
parent291650f52893682bfdb00a359461b6e4d5907a17 (diff)
Added hash seed randomizer and fixed truncation bug int variables
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.h2
-rw-r--r--src/codegen/codegen.c2
-rw-r--r--src/parser/parser_expr.c14
3 files changed, 6 insertions, 12 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)