[vlc-devel] [RFC v4] vlc_vector: add helpers for vectors
Romain Vimont
rom1v at videolabs.io
Sun Sep 2 12:01:22 CEST 2018
On Sat, Sep 01, 2018 at 12:16:54PM +0300, Rémi Denis-Courmont wrote:
> Le perjantaina 31. elokuuta 2018, 22.48.17 EEST Romain Vimont a écrit :
> > I'm not sure about the definition of "compatible", but I would say that
> > type* and void* are compatible types.
>
> No, unless type is void, they are not.
Do you think that using memcpy() would solve the strict aliasing
violation (since it uses char* which is allowed to alias)?
diff --git a/include/vlc_vector.h b/include/vlc_vector.h
index 64fe051739..58f3e4a7bb 100644
--- a/include/vlc_vector.h
+++ b/include/vlc_vector.h
@@ -134,7 +134,7 @@ vlc_vector_reallocarray_(void **pptr, size_t count, size_t size)
void *n = vlc_reallocarray(*pptr, count, size);
if (n)
/* replace ptr only on allocation success */
- *pptr = n;
+ memcpy(pptr, &n, sizeof(void *));
return n != NULL;
}
Otherwise, I have another solution (that I submitted as RFC v5): the
current implementation guarantees that the capacity is always smaller
than SIZE_MAX/2 (to avoid overflows on grow or index_of), so I take
advantage of the free MSB bit to report allocation failure.
More information about the vlc-devel
mailing list