Don't overalign _RuneStatePriv, it must share the alignment of mbstate_t
it aliased with. Assert that the alignment actually used reflects the alignment required by existing implementation and for newly build modules assert that it is at most the guaranteed alignment.
This commit is contained in:
parent
34a4ae727b
commit
b90f380e16
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: citrus_ctype_template.h,v 1.37 2019/07/28 14:26:08 christos Exp $ */
|
||||
/* $NetBSD: citrus_ctype_template.h,v 1.38 2020/06/02 01:30:31 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)2002 Citrus Project,
|
||||
|
@ -118,6 +118,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <stdalign.h>
|
||||
|
||||
/* prototypes */
|
||||
|
||||
|
@ -506,6 +507,10 @@ _FUNCNAME(ctype_getops)(_citrus_ctype_ops_rec_t *ops, size_t lenops,
|
|||
return (0);
|
||||
}
|
||||
|
||||
/* Ensure alignment matches guarantees from locale/multibyte.h */
|
||||
__CTASSERT(alignof(_ENCODING_STATE) <= alignof(int) ||
|
||||
alignof(_ENCODING_STATE) <= alignof(void *));
|
||||
|
||||
static int
|
||||
_FUNCNAME(ctype_init)(void ** __restrict cl,
|
||||
void * __restrict var, size_t lenvar, size_t lenps)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: multibyte.h,v 1.6 2013/08/18 20:03:48 joerg Exp $ */
|
||||
/* $NetBSD: multibyte.h,v 1.7 2020/06/02 01:30:31 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)2002 Citrus Project,
|
||||
|
@ -29,6 +29,8 @@
|
|||
#ifndef _MULTIBYTE_H_
|
||||
#define _MULTIBYTE_H_
|
||||
|
||||
#include <stdalign.h>
|
||||
|
||||
/* mbstate_t private */
|
||||
|
||||
#ifdef _BSD_MBSTATE_T_
|
||||
|
@ -38,9 +40,14 @@ typedef _BSD_MBSTATE_T_ mbstate_t;
|
|||
|
||||
typedef struct _RuneStatePriv {
|
||||
_RuneLocale *__runelocale;
|
||||
char __private __attribute__((__aligned__));
|
||||
char __private[];
|
||||
} _RuneStatePriv;
|
||||
|
||||
__CTASSERT(alignof(struct _RuneStatePriv) >= alignof(void *));
|
||||
__CTASSERT(sizeof(_RuneStatePriv) % alignof(void *) == 0);
|
||||
__CTASSERT(alignof(struct _RuneStatePriv) >= alignof(int));
|
||||
__CTASSERT(sizeof(_RuneStatePriv) % alignof(int) == 0);
|
||||
|
||||
typedef union _RuneState {
|
||||
mbstate_t __pad;
|
||||
struct _RuneStatePriv __priv;
|
||||
|
@ -91,7 +98,7 @@ _ps_to_private(mbstate_t *ps)
|
|||
{
|
||||
if (ps == NULL)
|
||||
return NULL;
|
||||
return (void *)&_ps_to_runestate(ps)->rs_private;
|
||||
return _ps_to_runestate(ps)->rs_private;
|
||||
}
|
||||
|
||||
static __inline void const *
|
||||
|
@ -99,7 +106,7 @@ _ps_to_private_const(mbstate_t const *ps)
|
|||
{
|
||||
if (ps == NULL)
|
||||
return NULL;
|
||||
return (void const *)&_ps_to_runestate_const(ps)->rs_private;
|
||||
return _ps_to_runestate_const(ps)->rs_private;
|
||||
}
|
||||
|
||||
static __inline void
|
||||
|
|
Loading…
Reference in New Issue