Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/usr.bin
Date: Thu, 19 Aug 2021 21:21:04 +0000
From: "Roland Illig" <rillig%netbsd.org@localhost>
Message-ID: <20210819212104.7C965FA97%cvs.NetBSD.org@localhost>
| mkdep: fix prototype of findcc
That broke the build.
| A function that modifies a string argument must not declare that
| argument as 'const char *', even if all callers (mkdep and lint) always
| pass it a modifiable string.
Apparently they don't (but they probably don't pass unmodifiable
strings containing spaces).
The right thing to do is to handle the FIXME in the comment,
and fix it, instead of enshrining it by changing the prototype.
Something like
char *
findcc(const char *progname)
{
char *path, *dir, *next;
char buffer[MAXPATHLEN];
size_t len;
if ((next = strchr(progname, ' ')) != NULL) {
if (next > progname)
len = (size_t)(next - progname);
else
return NULL;
} else
len = strlen(progname);
/* there could be a test that len <= MAXINT, but really... */
if (memchr(progname, '/', len) != NULL) {
path = strndup(progname, len);
if (access(path, X_OK) == 0)
return path;
free(path);
return NULL;
}
if (((path = getenv("PATH")) == NULL) ||
((path = strdup(path)) == NULL))
return NULL;
dir = path;
while (dir != NULL) {
if ((next = strchr(dir, ':')) != NULL)
*next++ = '\0';
if (snprintf(buffer, sizeof(buffer),
"%s/%.*s", dir, (int)len, progname) < (int)sizeof(buffer)) {
if (!access(buffer, X_OK)) {
free(path);
return strdup(buffer);
}
}
dir = next;
}
free(path);
return NULL;
}
That's untested, not even compile tested, and it should be before being
committed (fully tested, in a release build, with ATF tests run), but
something like that should work, and work without modifying the input
string, which should immediately go back to being const while this is being
worked out, to unbreak the build.
kre
ps: I cut & pasted the code from an xterm, so tabs will have been lost
all over the place. That needs fixing for sure.
Home |
Main Index |
Thread Index |
Old Index