Lars Schneider <larsxschnei...@gmail.com> writes:

> 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.

Reply via email to