The memcpy function technically requires both its pointer inputs to be non-null.
There is no special case for the length being 0. When running the example from
#2088 under UBSan, it detects this memcpy call as being performed with both null
source and destination pointers. It is unlikely any real world memcpy would
misbehave in this circumstance, but it is still good practice to avoid this.
if (!A) return A;
B = SparseMatrix_general_new(A->m, A->n, A->nz, A->type, A->size, A->format);
memcpy(B->ia, A->ia, sizeof(int)*((size_t)(A->m+1)));
- memcpy(B->ja, A->ja, sizeof(int)*((size_t)(A->ia[A->m])));
+ if (A->ia[A->m] != 0) {
+ memcpy(B->ja, A->ja, sizeof(int)*((size_t)(A->ia[A->m])));
+ }
if (A->a) memcpy(B->a, A->a, A->size*((size_t)A->nz));
B->property = A->property;
B->nz = A->nz;