Re: [eigen] Question regarding QtAllignedMalloc / qRealloc

[ Thread Index | Date Index | More Archives ]

Sorry for the late reply.

You're right, this function is completely buggy. I think that any
correct implementation has to call the preexisting qRealloc function,
see e.g. how our own handmade_aligned_realloc works.


2011/10/7 Schmidt, Michael <Michael.Schmidt@xxxxxxxxxxxxxxxxxxx>:
> Dear all,
> I just stumbled over the QtAlignedMalloc file and the qRealloc method
> provided therein. The function is implemented this way:
> void *qRealloc(void *ptr, size_t size)
> {
>   void* newPtr = Eigen::internal::aligned_malloc(size);
>   memcpy(newPtr, ptr, size);
>   Eigen::internal::aligned_free(ptr);
>   return newPtr;
> }
> My question is: Why can you do the memcpy in that way? If size is larger
> than the the block pointed to by ptr, memcpy will possibly access invalid
> memory locations, won't it?
> Best regards, Michael

Mail converted by MHonArc 2.6.19+