From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============6922990709327872347==" MIME-Version: 1.0 From: Alexander Cherepanov To: elfutils-devel@lists.fedorahosted.org Subject: Re: [PATCH] libdwfl: Fix wrong type to make gcc -fsanitize=undefined happy. Date: Thu, 23 Apr 2015 18:06:18 +0300 Message-ID: <55390A6A.4010509@openwall.com> In-Reply-To: 20150421202612.E9A172C3AC8@topped-with-meat.com --===============6922990709327872347== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On 2015-04-21 23:26, Roland McGrath wrote: > I think it's cleaner to do: > > [PATCH] libdwfl: Make dwfl_error.c C99-kosher. > > Signed-off-by: Roland McGrath > --- > libdwfl/ChangeLog | 7 +++++++ > libdwfl/dwfl_error.c | 21 +++++++++++++++++---- > 2 files changed, 24 insertions(+), 4 deletions(-) > > diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog > index d4cd3f5..045adb0 100644 > --- a/libdwfl/ChangeLog > +++ b/libdwfl/ChangeLog > @@ -1,3 +1,10 @@ > +2015-04-21 Roland McGrath > + > + * dwfl_error.c (struct msgtable): Break type definition out of > + the 'msgtable' initializer. > + (msgtable): Make it a union of struct msgtable and a char array. > + (msgstr): Use the full-table char array rather than the msg_0 entry. > + > 2015-04-02 Mark Wielaard > > * segment.c (insert): Check correct number of lookup_elts. > diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c > index d9ca9e7..f46b160 100644 > --- a/libdwfl/dwfl_error.c > +++ b/libdwfl/dwfl_error.c > @@ -1,5 +1,5 @@ > /* Error handling in libdwfl. > - Copyright (C) 2005-2010 Red Hat, Inc. > + Copyright (C) 2005-2015 Red Hat, Inc. > This file is part of elfutils. > > This file is free software; you can redistribute it and/or modify > @@ -54,18 +54,31 @@ dwfl_errno (void) > INTDEF (dwfl_errno) > > > -static const struct msgtable > +struct msgtable > { > #define DWFL_ERROR(name, text) char msg_##name[sizeof text]; > DWFL_ERRORS > #undef DWFL_ERROR > +}; > + > +static const union > +{ > + struct msgtable table; > + char strings[ > +#define DWFL_ERROR(name, text) sizeof text + > + DWFL_ERRORS > +#undef DWFL_ERROR > + + 0]; Extra plus in front of 0? Why not just use sizeof(struct msgtable)? > } msgtable =3D > { > + .table =3D > + { > #define DWFL_ERROR(name, text) text, > - DWFL_ERRORS > + DWFL_ERRORS > #undef DWFL_ERROR > + } > }; > -#define msgstr (&msgtable.msg_NOERROR[0]) > +#define msgstr (msgtable.strings) Something like can be done without unions: #define msgstr (*(char (*)[sizeof msgtable])&msgtable) AFACT it's well-defined C and permits to perform bound checking. -- = Alexander Cherepanov --===============6922990709327872347==--