Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/share/mk
> Date: Mon, 7 Aug 2023 23:58:50 +0200
> From: Tobias Nygren <tnn%NetBSD.org@localhost>
>
> Is this sort of fix acceptable for the above cases?
>
> + ptrdiff_t offset = pos - buf;
> new_buf = realloc(buf, buf_size);
> if (!new_buf)
> err(2, "realloc of linebuf to %zu bytes failed",
> buf_size);
> -
> +
> end = new_buf + buf_size;
> - pos = new_buf + (pos - buf);
> + pos = new_buf + offset;
> buf = new_buf;
Yes, this is a good approach.
Even if it's suboptimal in some cases, it is very easy to audit
mechanical changes, which is important if there are a lot of them.
Any further case-specific simplifications (like changing ptrdiff_t to
size_t, since it will always be nonnegative here; just using `size_t
offset = buf_size' before `buf_size *= 2', since since pos == end and
end == buf + buf_size) can be done afterward in a separate commit.
Home |
Main Index |
Thread Index |
Old Index