Source-Changes-D archive

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

Restoring pointers after realloc (was: Re: CVS commit: src/share/mk)



Am 07.08.2023 um 23:58 schrieb Tobias Nygren:
> Is this sort of fix acceptable for the above cases?
>
> +	ptrdiff_t offset = pos - buf;
>  	new_buf = realloc(buf, buf_size);
> -	pos = new_buf + (pos - buf);
> +	pos = new_buf + offset;

Yes.

Instead of ptrdiff_t, I prefer to use size_t to avoid having to include
<stddef.h>, even if that means an additional type cast at WARNS=6 level:

> +	size_t offset = (size_t)(pos - buf);

Roland



Home | Main Index | Thread Index | Old Index