The ubsan triggers:
UBSAN: Undefined behaviour in programs/ld-collate.c:862:5 null pointer passed as argument 2, nonnull attribute declared at unknown:0:0,
The memcpy is only requires if current 'weights' is nonnull, so
check it before calling it.
max += 10;
newp = (struct element_t **)
alloca (max * sizeof (struct element_t *));
- memcpy (newp, weights, cnt * sizeof (struct element_t *));
+ if (weights != NULL)
+ memcpy (newp, weights, cnt * sizeof (struct element_t *));
weights = newp;
}
weights[cnt++] = charelem;