Re: [PATCH v9 09/14] pkt-line: add packet_write_gently()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 6, 2016, 17:25 UTC
- Message-ID
- <xmqqy421l78m.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <B1968DDD-7EAA-477B-B088-5F2A83F29C8C@gmail.com>
Lars Schneider <larsxschneider@gmail.com> writes:
Show 10 quoted lines
> You are right. Would the solution below be acceptable?
> I would like to keep the `packet_size` variable as it eases the rest
> of the function.
>
>
> const size_t packet_size = size + 4;
>
> - if (packet_size > sizeof(packet_write_buffer))
> + if (size > sizeof(packet_write_buffer) - 4)
> return error("packet write failed - data exceeds max packet size");Sounds fine; packet_size may have invalid value if size is large enough but in such a case the function would return without using it, so no harm is expected, I would say. I'd prefer to see the definition of packet_size separate from the assignment of size + 4 to it in a case like this, though.