Re: [PATCH] mailsplit and mailinfo: gracefully handle NUL characters
- From
David Kastrup <dak@gnu.org>
- Date
- May 16, 2008, 14:14 UTC
- Message-ID
- <86wsluuyht.fsf@lola.quinscape.zz>
- In-Reply-To
- <a537dd660805160707y3830b164td0605a15e6ae05a5@mail.gmail.com>
"Brian Foster" <brian.foster@innova-card.com> writes:
Show 15 quoted lines
> I'd tend to write this in terms of pointers,
> something along the lines (untested):
>
> char *p, *endp;
>
> assert(1 <= size);
> p = buf;
> endp = p + (size-1);
> while (p < endp) {
> if ((c = getc(in)) == EOF || (*p++ = c) == '\n')
> break;
> }
> *p = '\0';
>
> return p - buf;Leave optimization to the compiler. Using pointer arithmetic more often than not screws up loop optimization and strength reduction.
-- David Kastrup