Skip to content

Commit 13a853a

Browse files
committed
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.
1 parent 4fee21c commit 13a853a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

unix/mkerrors.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ main(void)
738738
e = errors[i].num;
739739
if(i > 0 && errors[i-1].num == e)
740740
continue;
741-
strcpy(buf, strerror(e));
741+
(void)strncpy(buf, strerror(e), sizeof(buf) - 1);
742+
buf[sizeof(buf) - 1] = '\0';
742743
// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
743744
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
744745
buf[0] += a - A;
@@ -757,7 +758,8 @@ main(void)
757758
e = signals[i].num;
758759
if(i > 0 && signals[i-1].num == e)
759760
continue;
760-
strcpy(buf, strsignal(e));
761+
(void)strncpy(buf, strsignal(e), sizeof(buf) - 1);
762+
buf[sizeof(buf) - 1] = '\0';
761763
// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
762764
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
763765
buf[0] += a - A;

0 commit comments

Comments
 (0)