commit 49771f356fddda873405da2cc6aaffb2758abcbc (tree)
parent c1f3766f1c1a528ff24c24429298ff8ac162909f
Author: LemonBoy <thatlemon@gmail.com>
Date: Tue, 14 Jan 2020 21:23:11 +0100
Make sure @export symbol name is not empty
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -16766,6 +16766,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
if (!symbol_name)
return ira->codegen->invalid_instruction;
+ if (buf_len(symbol_name) < 1) {
+ ir_add_error(ira, name_inst,
+ buf_sprintf("exported symbol name cannot be empty"));
+ return ira->codegen->invalid_instruction;
+ }
+
GlobalLinkageId global_linkage_id;
if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))
return ira->codegen->invalid_instruction;
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
+ cases.addTest("@export with empty name string",
+ \\pub export fn entry() void { }
+ \\comptime {
+ \\ @export(entry, .{ .name = "" });
+ \\}
+ , &[_][]const u8{
+ "tmp.zig:3:5: error: exported symbol name cannot be empty",
+ });
+
cases.addTest("switch ranges endpoints are validated",
\\pub export fn entry() void {
\\ var x: i32 = 0;