Skip to content

Commit 59ef960

Browse files
committed
fixed: name overflow in struct name
1 parent c7c3917 commit 59ef960

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

compiler/src/polymorph.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,15 +1103,15 @@ b32 potentially_convert_function_to_polyproc(Context *context, AstFunction *func
11031103
// structures now have a delay instantiation phase and are not forced to be completed immediately.
11041104

11051105
char* build_poly_struct_name(Context *context, char *name, Type* type) {
1106-
char name_buf[256];
1107-
fori (i, 0, 256) name_buf[i] = 0;
1106+
char name_buf[512];
1107+
fori (i, 0, 512) name_buf[i] = 0;
11081108

11091109

11101110
// Special case for `? T`
11111111
if (type->kind == Type_Kind_Union
11121112
&& type->Union.constructed_from == context->builtins.optional_type) {
1113-
strncat(name_buf, "? ", 255);
1114-
strncat(name_buf, type_get_name(context, type->Union.poly_sln[0].type), 255);
1113+
strncat(name_buf, "? ", 511);
1114+
strncat(name_buf, type_get_name(context, type->Union.poly_sln[0].type), 511);
11151115

11161116
return bh_aprintf(context->gp_alloc, "%s", name_buf);
11171117
}
@@ -1121,17 +1121,17 @@ char* build_poly_struct_name(Context *context, char *name, Type* type) {
11211121
if (type->kind == Type_Kind_Union) slns = type->Union.poly_sln;
11221122

11231123

1124-
strncat(name_buf, name, 255);
1125-
strncat(name_buf, "(", 255);
1124+
strncat(name_buf, name, 511);
1125+
strncat(name_buf, "(", 511);
11261126
bh_arr_each(AstPolySolution, ptype, slns) {
11271127
if (ptype != slns)
1128-
strncat(name_buf, ", ", 255);
1128+
strncat(name_buf, ", ", 511);
11291129

11301130
// This logic will have to be other places as well.
11311131

11321132
switch (ptype->kind) {
11331133
case PSK_Undefined: assert(0); break;
1134-
case PSK_Type: strncat(name_buf, type_get_name(context, ptype->type), 255); break;
1134+
case PSK_Type: strncat(name_buf, type_get_name(context, ptype->type), 511); break;
11351135
case PSK_Value: {
11361136
// FIX
11371137
AstNode* value = strip_aliases((AstNode *) ptype->value);
@@ -1155,7 +1155,7 @@ char* build_poly_struct_name(Context *context, char *name, Type* type) {
11551155
}
11561156
}
11571157
}
1158-
strncat(name_buf, ")", 255);
1158+
strncat(name_buf, ")", 511);
11591159

11601160
return bh_aprintf(context->gp_alloc, "%s", name_buf);
11611161
}

core/container/iter.onyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,9 @@ prod :: (x: $I1/Iterable, y_iter: Iterator($Y)) => {
10111011
ctx => {
10121012
switch ctx.y_val {
10131013
case .Some as y {
1014-
next(ctx.x_iter)->with([x] {
1014+
if next(ctx.x_iter) as x {
10151015
return Optional.make(Pair.make(x, y))
1016-
})
1016+
}
10171017
}
10181018

10191019
case .None do return .None

core/conv/parse.onyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ parse_any :: macro (v: &$T, to_parse: str, string_allocator := context.allocator
1818

1919
#overload
2020
parse_any :: (target: rawptr, data_type: type_expr, to_parse: str, string_allocator := context.allocator) -> bool {
21-
custom_parsers->get(data_type)->with([parser] {
21+
if custom_parsers->get(data_type) as parser {
2222
return parser(target, to_parse, string_allocator);
23-
});
23+
}
2424

2525
use runtime.info {*};
2626
info := get_type_info(data_type);

tests/aoc-2020/day17.onyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ get_neighbor_count :: (cubes: &Map(CubePos, CubeState), pos: CubePos) -> u32 {
4242
for x in -1 .. 2 do for y in -1 .. 2 do for z in -1 .. 2 do for w in -1 .. 2 {
4343
if x == 0 && y == 0 && z == 0 && w == 0 do continue;
4444
key := CubePos.{ pos.x + x, pos.y + y, pos.z + z, pos.w + w };
45-
map.get(cubes, key)->with([s] {
45+
if map.get(cubes, key) as s {
4646
if s.alive do count += 1;
47-
});
47+
}
4848
}
4949

5050
return count;

0 commit comments

Comments
 (0)