> +void
> +tbufnew(size_t siz) {
Seems pointless noise. Just do `siz ? (siz*2) : 128` when extending.
> + tbuf.buf = (char *)xmalloc(siz);
Don't cast malloc:
https://c-faq.com/malloc/mallocnocast.html
> +size_t
> +tbuflen(void) {
> + return tbuf.len;
> +}
I'd just make the object available instead of dancing around.
Braces for functions also should go on their own line.
> + if (tbuf.siz - tbuf.len < n) {
> + tbuf.siz *= 2;
What guarantees that `siz * 2` will make enough space for `n`? I don't
see any, which makes the memcpy below a buffer overflow.
> + tbuf.buf = xrealloc(tbuf.buf, tbuf.siz);
I'm highly skeptical of this. If the other end is not able to keep up
that doesn't mean we should unboundedly keep hogging up memory.
https://medium.com/_AT_jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7#cdaf
(replace `medium.com` with `scribe.rip` for a debloated version)
- NRK
Received on Fri Jun 28 2024 - 11:55:33 CEST