From 304f187cdba97b70a86421a915114c328653f0de Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 6 Jun 2023 13:44:54 +0000 Subject: [PATCH] unix: replace use of strcpy in mkerrors.sh On OpenBSD-current, clang emits a warning message to standard output for the use of strcpy, e.g.: _errors.c(/tmp/_errors-673190.o:(main)): warning: strcpy() is almost always misused, please use strlcpy() This message makes it into the Go source being created, causing gofmt to error on the invalid syntax, and leaving the zerrors file empty. Using strlcpy would be preferred here, but strncpy is enough to silence this message, and is more portable. Change-Id: I16404d74c4406dadda87f211fc0ba062de0d11ac GitHub-Last-Rev: a43b6fbc1b3c2bd9ee473d0dac9a73381e196abf GitHub-Pull-Request: golang/sys#147 Reviewed-on: https://go-review.googlesource.com/c/sys/+/468399 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: David Chase --- unix/mkerrors.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index be0423e68..315646271 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -741,7 +741,8 @@ main(void) e = errors[i].num; if(i > 0 && errors[i-1].num == e) continue; - strcpy(buf, strerror(e)); + strncpy(buf, strerror(e), sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; // 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 +761,8 @@ main(void) e = signals[i].num; if(i > 0 && signals[i-1].num == e) continue; - strcpy(buf, strsignal(e)); + strncpy(buf, strsignal(e), sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; // 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;