Skip to content

Commit 304f187

Browse files
jrickgopherbot
authored andcommitted
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: a43b6fb GitHub-Pull-Request: #147 Reviewed-on: https://go-review.googlesource.com/c/sys/+/468399 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 81c8a6c commit 304f187

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

unix/mkerrors.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ main(void)
741741
e = errors[i].num;
742742
if(i > 0 && errors[i-1].num == e)
743743
continue;
744-
strcpy(buf, strerror(e));
744+
strncpy(buf, strerror(e), sizeof(buf) - 1);
745+
buf[sizeof(buf) - 1] = '\0';
745746
// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
746747
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
747748
buf[0] += a - A;
@@ -760,7 +761,8 @@ main(void)
760761
e = signals[i].num;
761762
if(i > 0 && signals[i-1].num == e)
762763
continue;
763-
strcpy(buf, strsignal(e));
764+
strncpy(buf, strsignal(e), sizeof(buf) - 1);
765+
buf[sizeof(buf) - 1] = '\0';
764766
// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
765767
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
766768
buf[0] += a - A;

0 commit comments

Comments
 (0)