Message ID | 20250507142110.3452012-8-adhemerval.zanella@linaro.org |
---|---|
State | New |
Headers | show |
Series | Add initial support for --enable-ubsan | expand |
On Mai 07 2025, Adhemerval Zanella wrote: > diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c > index 4fa08bd273..5ed03f4cbf 100644 > --- a/locale/programs/ld-collate.c > +++ b/locale/programs/ld-collate.c > @@ -1554,7 +1554,7 @@ collate_finish (struct localedef_t *locale, const struct charmap_t *charmap) > The multibyte case is easy. We simply sort into an array with > 256 elements. */ > struct locale_collate_t *collate = locale->categories[LC_COLLATE].collate; > - int mbact[nrules]; > + int mbact[nrules == 0 ? 1 : nrules]; nrules is guaranteed to be at most sizeof (((struct element_t *) 0)->used_in_level) * 8, so this can use a fixed array.
* Adhemerval Zanella: > The ubsan triggers: > > UBSAN: Undefined behaviour in programs/ld-collate.c:1557:7 variable length array bound evaluates to non-positive value 0 > > The VLA is allocated with nrules being 0. To simplify the fix, > just allocate one for this case. Typo in commit subject: local[]e
diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c index 4fa08bd273..5ed03f4cbf 100644 --- a/locale/programs/ld-collate.c +++ b/locale/programs/ld-collate.c @@ -1554,7 +1554,7 @@ collate_finish (struct localedef_t *locale, const struct charmap_t *charmap) The multibyte case is easy. We simply sort into an array with 256 elements. */ struct locale_collate_t *collate = locale->categories[LC_COLLATE].collate; - int mbact[nrules]; + int mbact[nrules == 0 ? 1 : nrules]; int wcact; int mbseqact; int wcseqact;