Page MenuHomeFreeBSD

pwd(1): De-obfuscate, style(9)
Needs ReviewPublic

Authored by olce on Tue, Sep 15, 4:07 PM.
Tags
None
Referenced Files
F172292986: D59709.id186784.diff
Thu, Sep 17, 12:49 PM
Unknown Object (File)
Wed, Sep 16, 5:54 PM
Unknown Object (File)
Wed, Sep 16, 3:44 AM
Unknown Object (File)
Wed, Sep 16, 2:48 AM
Subscribers

Details

Reviewers
des
emaste
Summary

In getcwd_logical(), test for a '.' or '..' component in the most
straightforward and intelligible way possible. This removes
a superfluous retest of the the first character being '.' when the first
one did not pass and, more importantly, prevents the second test from
relying on a side-effect in the first.

While here, for better clarity, remove another side-effect in the
initialization statement of the inner loop, by incrementing 'p' before
the loop and leaving a small comment explaining why.

While here, test explicitly that pointed 'char' values are not 0 ('\0')
(style(9)).

No functional change (intended).

Fixes: 2df923c5d2d0 ("pwd: Clean up and adopt POSIX semantics")
MFC after: 3 days
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76937
Build 73820: arc lint + arc unit

Event Timeline

olce requested review of this revision.Tue, Sep 15, 4:07 PM

The proposed change is fine with me, but maybe still more clever than necessary.

bin/pwd/pwd.c
54

tbh I find the for loop here slightly less clear than

q = p;
while (*q != '\0` && *q != '/')
        q++;

But what about just using strcspn, something like

len = strcspn(p, "/");
if ((len == 1 && p[0] == '.') || (len == 2 && p[0] == '.' && p[1] == '.'))
56

If keeping this form, perhaps p[0] instead of *p?