From 8c0f635c75c721d7ae1c71cf97cedc6f8fc0c6f5 Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Mon, 5 Jun 2023 23:01:52 +0200 Subject: [PATCH] unix: fix mkerrors.sh on OpenBSD by using strlcpy On OpenBSD, strcpy causes an error message output that recommends the use of strlcpy[0]. Here, the result was that this output became part of the generated program code, causing gofmt to fail and create an empty zerrors_openbsd_GOARCH.go file. An ifdef guard has been added within the C code which uses the desired strlcpy function under OpenBSD. Other operating systems continue to use strcpy. [0] https://github.com/openbsd/src/blob/958bc3ae91838214c6d3bb7efc272663a5df7b01/lib/libc/string/strcpy.c#L34-L37 --- unix/mkerrors.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index be0423e685..e11e67cf16 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -741,7 +741,11 @@ main(void) e = errors[i].num; if(i > 0 && errors[i-1].num == e) continue; +#ifdef __OpenBSD__ + strlcpy(buf, strerror(e), sizeof(buf)); +#else strcpy(buf, strerror(e)); +#endif /* __OpenBSD __*/ // lowercase first letter: Bad -> bad, but STREAM -> STREAM. if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) buf[0] += a - A; @@ -760,7 +764,11 @@ main(void) e = signals[i].num; if(i > 0 && signals[i-1].num == e) continue; +#ifdef __OpenBSD__ + strlcpy(buf, strsignal(e), sizeof(buf)); +#else strcpy(buf, strsignal(e)); +#endif /* __OpenBSD __*/ // lowercase first letter: Bad -> bad, but STREAM -> STREAM. if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) buf[0] += a - A;