From 49771f356fddda873405da2cc6aaffb2758abcbc Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 14 Jan 2020 21:23:11 +0100 Subject: [PATCH] Make sure @export symbol name is not empty --- src/ir.cpp | 6 ++++++ test/compile_errors.zig | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index bbf56fd08d..d871aa27a0 100644 --- 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 index 6552ad2413..3ce5bd8801 100644 --- 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;