Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor strchr(p, 0) -> p + strlen(p) #1022

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sys/net/iflib.c
Original file line number Diff line number Diff line change
Expand Up @@ -6740,7 +6740,7 @@ mp_ndesc_handler(SYSCTL_HANDLER_ARGS)
break;
if (i)
strcat(buf, ",");
sprintf(strchr(buf, 0), "%d", ndesc[i]);
sprintf(buf + strlen(buf), "%d", ndesc[i]);
}

rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
Expand Down
5 changes: 2 additions & 3 deletions usr.bin/patch/pch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,9 +1478,8 @@ do_ed_script(void)
if (*t == 's') {
for (;;) {
continuation = 0;
t = strchr(buf, '\0') - 1;
while (--t >= buf && *t == '\\')
continuation = !continuation;
for (t = buf; *t && *t == '\\'; t++)
continuation ^= 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why continuation ^= 1? This makes understanding the logic even harder. IMO the previous one is better here.

if (!continuation ||
pgets(true) == 0)
break;
Expand Down
4 changes: 2 additions & 2 deletions usr.bin/systat/netstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ inetprint(struct sockaddr *sa, const char *proto)
break;
}
snprintf(line, sizeof(line), "%.*s.", 16, inetname(sa));
cp = strchr(line, '\0');
cp = line + strlen(line);
if (!nflag && port)
sp = getservbyport(port, proto);
if (sp || port == 0)
Expand All @@ -551,7 +551,7 @@ inetprint(struct sockaddr *sa, const char *proto)
snprintf(cp, sizeof(line) - (cp - line), "%d",
ntohs((u_short)port));
/* pad to full column to clear any garbage */
cp = strchr(line, '\0');
cp = line + strlen(line);
while (cp - line < 22)
*cp++ = ' ';
line[22] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion usr.sbin/bhyve/pci_passthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ passthru_lookup_pptdev(const char *name, int *bus, int *slot, int *func)
* the driver name. Walk backwards from the end of the name to
* find the start of the unit.
*/
cp = strchr(name, '\0');
cp = cp + strlen(cp);
assert(cp != NULL);
while (cp != name && isdigit(cp[-1]))
cp--;
Expand Down
2 changes: 1 addition & 1 deletion usr.sbin/lpr/chkprintcap/skimprintcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ skim_printcap(const char *pcap_fname, int verbosity)
if (lastchar != NULL)
*lastchar = '\0';
else {
lastchar = strchr(curline, '\0');
lastchar = curline + strlen(lastchar);
missing_nl = 1;
}
if (curline < lastchar)
Expand Down
4 changes: 2 additions & 2 deletions usr.sbin/lpr/common_source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ trstat_write(struct printer *pp, tr_sendrecv sendrecv, size_t bytecnt,
const char *lprhost, *recvdev, *recvhost, *rectype;
const char *sendhost, *statfname;
#define UPD_EOSTAT(xStr) do { \
eostat = strchr(xStr, '\0'); \
remspace = eostat - xStr; \
remspace = strlen(xStr); \
eostat = xStr + remspace; \
} while(0)

lpd_gettime(&pp->tr_done, NULL, (size_t)0);
Expand Down
4 changes: 2 additions & 2 deletions usr.sbin/pciconf/pciconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,9 @@ load_vendors(void)

if ((ch = strchr(buf, '#')) != NULL)
*ch = '\0';
ch = strchr(buf, '\0') - 1;
ch = buf + strlen(buf);
while (ch > buf && isspace(*ch))
*ch-- = '\0';
*--ch = '\0';
if (ch <= buf)
continue;

Expand Down