Module Name:    src
Committed By:   joerg
Date:           Tue Jun  2 01:30:31 UTC 2020

Modified Files:
        src/lib/libc/citrus: citrus_ctype_template.h
        src/lib/libc/locale: multibyte.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/citrus/citrus_ctype_template.h
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/multibyte.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/citrus/citrus_ctype_template.h
diff -u src/lib/libc/citrus/citrus_ctype_template.h:1.37 src/lib/libc/citrus/citrus_ctype_template.h:1.38
--- src/lib/libc/citrus/citrus_ctype_template.h:1.37	Sun Jul 28 14:26:08 2019
+++ src/lib/libc/citrus/citrus_ctype_template.h	Tue Jun  2 01:30:31 2020
@@ -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_op
 	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)

Index: src/lib/libc/locale/multibyte.h
diff -u src/lib/libc/locale/multibyte.h:1.6 src/lib/libc/locale/multibyte.h:1.7
--- src/lib/libc/locale/multibyte.h:1.6	Sun Aug 18 20:03:48 2013
+++ src/lib/libc/locale/multibyte.h	Tue Jun  2 01:30:31 2020
@@ -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

Reply via email to