I think following is better.
if (c == '\n')
{
if (buffer) {
buffer[i-1] = '\0';
return buffer;
}
return strdup("");
}
Ginn
On Feb 13, 2009, at 2:21 PM, Takao Fujiwara - Tokyo S/W Center wrote:
> libproxy demo is always failed because the malloc values are not
> correct.
> This patch fixes the end of string.
> --- libproxy-0.2.3/src/bin/proxy.c.orig 2009-02-13
> 14:27:33.843552000 +0900
> +++ libproxy-0.2.3/src/bin/proxy.c 2009-02-13 14:34:44.181853000 +0900
> @@ -47,7 +47,12 @@ readline(int fd)
>
> // Receive a single character, check for newline or EOF
> if (read(fd, &c, 1) != 1) return buffer;
> - if (c == '\n') return buffer ? buffer : strdup("");
> + if (c == '\n')
> + {
> + if (buffer)
> + buffer[i-1] = '\0';
> + return buffer ? buffer : strdup("");
> + }
>
> // Allocate new buffer if we need
> if (i % 1024 == 1)
--------
Ginn Chen
Software Engineer, Browser Team
Sun Microsystems, Inc.
Phone: x82869 / +86-10-62673869
Fax: +86-10-62780969