Re: [PATCH] off-by-one bugs found by valgrind
- From
Horst von Brand <vonbrand@inf.utfsm.cl>
- Date
- Dec 22, 2005, 00:27 UTC
- Message-ID
- <200512220027.jBM0RetQ003481@laptop11.inf.utfsm.cl>
- In-Reply-To
- <junkio@cox.net>
Junio C Hamano <junkio@cox.net> wrote:
> Pavel Roskin <proski@gnu.org> writes:
[...]
Show 8 quoted lines
> > quote_c_style_counted() in quote.c uses a dangerous construct, when a
> > variable is incremented once and used twice in the same expression.
>
> Sorry, I do not follow you. Isn't && a sequence point?
>
> > - for (sp = name; (ch = *sp++) && (sp - name) <= namelen; ) {
> > -
> > + for (sp = name; sp < name + namelen; sp++) {Yes, it is, so it doesn't fix any bugs; but Pavel's version is definitely more readable.
-- Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513