back to square 2
Denys Vlasenko
vda.linux at googlemail.com
Sun Jun 22 16:40:01 UTC 2008
On Sunday 22 June 2008 16:36, walter harms wrote:
> Hello Denys,hi list
> i have still no clue why the error occurs.
> while searching i notices something else:
>
>
> static char *prev_line(char *p) // return pointer first char prev line
> {
> p = begin_line(p); // goto begining of cur line
> if (p[-1] == '\n' && p > text)
> p--; // step to prev line
> p = begin_line(p); // goto begining of prev line
> return p;
> }
>
> static char *next_line(char *p) // return pointer first char next line
> {
> p = end_line(p);
> if (*p == '\n' && p < end - 1)
> p++; // step to next line
> return p;
> }
>
>
> please take a look at the if().
>
> if (p[-1] == '\n' && p > text)
> p--; // step to prev line
>
> access to p[-1] and then checking that p is valid ?
> Is there any guarantee that p>text will be evaluated first ?
No, there is a guarantee that p[-1] == '\n' will be evaluated first.
In C, in (a && b) a is evaluated first, and if it's false,
b won't be evaluated.
>
> i would suggest:
> if ( p == text ) return p;
> if (p[-1] == '\n') p--;
> same goes for next_line().
I just swapped a and b in (a && b) here. Thanks!
--
vda
More information about the busybox
mailing list