authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-06 23:59:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-10 13:12:16-07:00
logdfee782d7c30e2ff84060833be375e8cdf92e3be
tree1d3c1a7b2cb86ac4648c2279be5df9e669eb3968
parent53f74d6a04377c9e0d7c3affd32fceea0fd51454

compiler_rt: provide strncpy impl for ssp


1 files changed, 9 insertions(+), 2 deletions(-)

lib/compiler_rt/ssp.zig+9-2
......@@ -16,7 +16,6 @@ const std = @import("std");
1616const common = @import("./common.zig");
1717const builtin = @import("builtin");
1818
19extern fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8;
2019extern fn memset(dest: ?[*]u8, c: u8, n: usize) callconv(.C) ?[*]u8;
2120extern fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8;
2221extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8;
......@@ -66,8 +65,16 @@ fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.C) [
6665}
6766
6867fn __strncpy_chk(dest: [*:0]u8, src: [*:0]const u8, n: usize, dest_n: usize) callconv(.C) [*:0]u8 {
68 @setRuntimeSafety(false);
6969 if (dest_n < n) __chk_fail();
70 return strncpy(dest, src, n);
70 var i: usize = 0;
71 while (i < n and src[i] != 0) : (i += 1) {
72 dest[i] = src[i];
73 }
74 while (i < n) : (i += 1) {
75 dest[i] = 0;
76 }
77 return dest;
7178}
7279
7380fn __strcat_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.C) [*:0]u8 {