Re: [PATCH] Rename read_pipe() with read_fd() and make its buffer nul-terminated.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2007/7/18, Junio C Hamano <gitster@xxxxxxxxx>:

>       unsigned long size = *return_size;
>       ssize_t iret;
>       unsigned long off = 0;
>
> +     if (!buf || size <= 1) {
> +             size = alloc_nr(size);
> +             buf = xrealloc(buf, size);
> +     }
> +

Hmph.  The reason this is not "!size" is because you would want
more than one.  As your plan is to use this mostly for the -F
option of "tag/commit", I suspect using a bit larger default,
such as 80 (just a line), or probably 1k (most log messages
would fit in such a buffer), would be more practical.

The true reason is because I before tried using (size-1) instead of (size)
in xread(..., size - off), and then I forgot to remove that condition. Sorry.


>       do {
>               iret = xread(fd, buf + off, size - off);
>               if (iret > 0) {
>                       off += iret;
>                       if (off == size) {
> -                             size *= 2;
> +                             size = alloc_nr(size);
>                               buf = xrealloc(buf, size);
>                       }
>               }
>       } while (iret > 0);
>
> +     if (off == size)
> +             buf = xrealloc(buf, size + 1);
> +     buf[off] = '\0';
> +

I wonder if doing xread(... (size-1) - off) in the loop would
ensure (off <= size-1) here.  You also would need to update the
realloc condition inside loop if you do so.

I have chosen that solution to leave the code easy to read, but the
(size-1) version will avoid that additional (but non-frequent) realloc.

I will resend the fixed patch along with the builtin-tag.c one.
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux