Skip to content

Commit

Permalink
unix: replace use of strcpy in mkerrors.sh
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrick committed Feb 15, 2023
1 parent 4fee21c commit 13a853a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions unix/mkerrors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ main(void)
e = errors[i].num;
if(i > 0 && errors[i-1].num == e)
continue;
strcpy(buf, strerror(e));
(void)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;
Expand All @@ -757,7 +758,8 @@ main(void)
e = signals[i].num;
if(i > 0 && signals[i-1].num == e)
continue;
strcpy(buf, strsignal(e));
(void)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;
Expand Down

0 comments on commit 13a853a

Please sign in to comment.