str(r)chr: Replace union abuse with __DECONST
Writing one union member and reading another is technically illegal C, although we do it in many places in the tree. Use the __DECONST macro instead, which is (technically) a valid C construct. Trivial style(9) cleanups to touched lines while here. Sponsored by: Dell EMC Isilon
This commit is contained in:
parent
cf823003a7
commit
3d825c42ca
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334624
@ -36,19 +36,16 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/libkern.h>
|
||||
|
||||
char *
|
||||
strchr(const char *p, int ch)
|
||||
strchr(const char *cp, int ch)
|
||||
{
|
||||
union {
|
||||
const char *cp;
|
||||
char *p;
|
||||
} u;
|
||||
char *p;
|
||||
|
||||
u.cp = p;
|
||||
for (;; ++u.p) {
|
||||
if (*u.p == ch)
|
||||
return(u.p);
|
||||
if (*u.p == '\0')
|
||||
return(NULL);
|
||||
p = __DECONST(char *, cp);
|
||||
for (;; ++p) {
|
||||
if (*p == ch)
|
||||
return (p);
|
||||
if (*p == '\0')
|
||||
return (NULL);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
@ -36,20 +36,16 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/libkern.h>
|
||||
|
||||
char *
|
||||
strrchr(const char *p, int ch)
|
||||
strrchr(const char *cp, int ch)
|
||||
{
|
||||
union {
|
||||
const char *cp;
|
||||
char *p;
|
||||
} u;
|
||||
char *save;
|
||||
char *p, *save;
|
||||
|
||||
u.cp = p;
|
||||
for (save = NULL;; ++u.p) {
|
||||
if (*u.p == ch)
|
||||
save = u.p;
|
||||
if (*u.p == '\0')
|
||||
return(save);
|
||||
p = __DECONST(char *, cp);
|
||||
for (save = NULL;; ++p) {
|
||||
if (*p == ch)
|
||||
save = p;
|
||||
if (*p == '\0')
|
||||
return (save);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user