Index: lib/libc/stdio/findfp.c =================================================================== --- lib/libc/stdio/findfp.c +++ lib/libc/stdio/findfp.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -96,11 +97,22 @@ struct glue *g; static FILE empty = { ._fl_mutex = PTHREAD_MUTEX_INITIALIZER }; FILE *p; + size_t align; - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); + /* + * FILE has a mbstate_t variable. This variable tries to be int64_t + * aligned through its definition. int64_t may be larger than void *, + * which is the size traditionally used for ALIGNBYTES. So, use our own + * rounding instead of the MI ALIGN macros. If for some reason + * ALIGNBYTES is larger than int64_t, respect that too. There appears to + * be no portable way to ask for FILE's alignment requirements other + * than just knowing here. + */ + align = MAX(ALIGNBYTES, sizeof(int64_t)); + g = (struct glue *)malloc(sizeof(*g) + align + n * sizeof(FILE)); if (g == NULL) return (NULL); - p = (FILE *)ALIGN(g + 1); + p = (FILE *)roundup((uintptr_t)(g + 1), align); g->next = NULL; g->niobs = n; g->iobs = p;