Re: [PATCH] diff-cache path restriction fix.
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- May 25, 2005, 01:00 UTC
- Message-ID
- <Pine.LNX.4.58.0505241757280.2307@ppc970.osdl.org>
- In-Reply-To
- <7vu0ksrv1v.fsf@assigned-by-dhcp.cox.net>
On Tue, 24 May 2005, Junio C Hamano wrote:
> > It advertises the path restriction in documentation and usage > string, but the argument parsing code was not updated and was > causing it to refuse to run. One liner fix is here.
No, it's more broken than that. Look at how it uses "argv[1]" for the tree SHA1, then does "argv++" and then uses "argv[1]" (which is a totally different argument entirely) for error reporting when the tree SHA1 is bad
> - while (argc > 2) {
> + while (1 < argc && argv[1][0] == '-') {Btw, that "1 < argc" order is very unintuitive to most humans. Like it or not, people get used to things one way, and have a hard time seeing what it means when it's the other way around.
And when people have a hard time seeing what it means, you get more bugs.
This is why it is _not_ better to do
if (1 == a)
like some people teach, even if that protects against the "single equal sign" bug. There are better ways to protect against that one bug (like having compiler warnings enabled) that don't make the code less obvious.
Linus