From: Andreas Jaeger <aj@suse.de>
To: GNU libc hacker <libc-hacker@sources.redhat.com>
Subject: Re: FYI: GCC warnings about strict-aliasing violation in glibc
Date: Sun, 10 Nov 2002 02:18:00 -0000 [thread overview]
Message-ID: <u8y9816842.fsf@gromit.moeb> (raw)
In-Reply-To: <u8el9t7psz.fsf@gromit.moeb> (Andreas Jaeger's message of "Sun, 10 Nov 2002 10:10:52 +0100")
Here's a fix to get rid of a number of these warnings. Ok to commit?
Andreas
2002-11-10 Andreas Jaeger <aj@suse.de>
* nss/getXXent.c (GETFUNC_NAME): Use union type to avoid strict
aliasing problem.
* nss/getXXbyYY_r.c (INTERNAL): Likewise.
* nss/getnssent_r.c (__nss_getent_r): Likewise.
(__nss_setent): Likewise.
(__nss_getent_r): Likewise.
============================================================
Index: nss/getXXent.c
--- nss/getXXent.c 1 Nov 2002 20:43:39 -0000 1.14
+++ nss/getXXent.c 10 Nov 2002 09:50:49 -0000
@@ -70,7 +70,12 @@ LOOKUP_TYPE *
GETFUNC_NAME (void)
{
static size_t buffer_size;
- static LOOKUP_TYPE resbuf;
+ static union
+ {
+ LOOKUP_TYPE l;
+ void *ptr;
+ } resbuf;
+
LOOKUP_TYPE *result;
int save;
@@ -79,7 +84,7 @@ GETFUNC_NAME (void)
result = (LOOKUP_TYPE *)
__nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
- (void **) &resbuf, &buffer, BUFLEN, &buffer_size,
+ &resbuf.ptr, &buffer, BUFLEN, &buffer_size,
H_ERRNO_VAR);
save = errno;
============================================================
Index: nss/getXXbyYY_r.c
--- nss/getXXbyYY_r.c 12 Sep 2002 05:14:59 -0000 1.47
+++ nss/getXXbyYY_r.c 10 Nov 2002 09:50:49 -0000
@@ -130,7 +130,12 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, L
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
- lookup_function fct;
+ union
+ {
+ lookup_function l;
+ void *ptr;
+ } fct;
+
int no_more;
enum nss_status status = NSS_STATUS_UNAVAIL;
#ifdef USE_NSCD
@@ -175,13 +180,13 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, L
if (startp == NULL)
{
- no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, (void **) &fct);
+ no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, &fct.ptr);
if (no_more)
startp = (service_user *) -1l;
else
{
startp = nip;
- start_fct = fct;
+ start_fct = fct.l;
#ifdef NEED__RES
/* The resolver code will really be used so we have to
@@ -201,7 +206,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, L
}
else
{
- fct = start_fct;
+ fct.l = start_fct;
no_more = (nip = startp) == (service_user *) -1l;
}
@@ -211,7 +216,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, L
any_service = true;
#endif
- status = DL_CALL_FCT (fct, (ADD_VARIABLES, resbuf, buffer, buflen,
+ status = DL_CALL_FCT (fct.l, (ADD_VARIABLES, resbuf, buffer, buflen,
&errno H_ERRNO_VAR));
/* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
@@ -227,7 +232,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, L
break;
no_more = __nss_next (&nip, REENTRANT_NAME_STRING,
- (void **) &fct, status, 0);
+ &fct.ptr, status, 0);
}
#ifdef HANDLE_DIGITS_DOTS
============================================================
Index: nss/getnssent_r.c
--- nss/getnssent_r.c 12 Sep 2002 02:58:21 -0000 1.4
+++ nss/getnssent_r.c 10 Nov 2002 09:50:49 -0000
@@ -53,7 +53,11 @@ __nss_setent (const char *func_name, db_
service_user **last_nip, int stayopen, int *stayopen_tmp,
int res)
{
- setent_function fct;
+ union
+ {
+ setent_function f;
+ void *ptr;
+ } fct;
int no_more;
if (res && (_res.options & RES_INIT) == 0
@@ -65,7 +69,7 @@ __nss_setent (const char *func_name, db_
/* Cycle through the services and run their `setXXent' functions until
we find an available service. */
- no_more = setup (func_name, lookup_fct, (void **) &fct, nip,
+ no_more = setup (func_name, lookup_fct, &fct.ptr, nip,
startp, 1);
while (! no_more)
{
@@ -73,11 +77,11 @@ __nss_setent (const char *func_name, db_
enum nss_status status;
if (stayopen_tmp)
- status = DL_CALL_FCT (fct, (*stayopen_tmp));
+ status = DL_CALL_FCT (fct.f, (*stayopen_tmp));
else
- status = DL_CALL_FCT (fct, (0));
+ status = DL_CALL_FCT (fct.f, (0));
- no_more = __nss_next (nip, func_name, (void **) &fct,
+ no_more = __nss_next (nip, func_name, &fct.ptr,
status, 0);
if (is_last_nip)
*last_nip = *nip;
@@ -93,7 +97,11 @@ __nss_endent (const char *func_name, db_
service_user **nip, service_user **startp,
service_user **last_nip, int res)
{
- endent_function fct;
+ union
+ {
+ endent_function f;
+ void *ptr;
+ } fct;
int no_more;
if (res && (_res.options & RES_INIT) == 0
@@ -104,17 +112,17 @@ __nss_endent (const char *func_name, db_
}
/* Cycle through all the services and run their endXXent functions. */
- no_more = setup (func_name, lookup_fct, (void **) &fct, nip, startp, 1);
+ no_more = setup (func_name, lookup_fct, &fct.ptr, nip, startp, 1);
while (! no_more)
{
/* Ignore status, we force check in __NSS_NEXT. */
- DL_CALL_FCT (fct, ());
+ DL_CALL_FCT (fct.f, ());
if (*nip == *last_nip)
/* We have processed all services which were used. */
break;
- no_more = __nss_next (nip, func_name, (void **) &fct, 0, 1);
+ no_more = __nss_next (nip, func_name, &fct.ptr, 0, 1);
}
*last_nip = *nip = NULL;
}
@@ -129,7 +137,11 @@ __nss_getent_r (const char *getent_func_
void *resbuf, char *buffer, size_t buflen,
void **result, int *h_errnop)
{
- getent_function fct;
+ union
+ {
+ getent_function f;
+ void *ptr;
+ } fct;
int no_more;
enum nss_status status;
@@ -147,13 +159,13 @@ __nss_getent_r (const char *getent_func_
/* Run through available functions, starting with the same function last
run. We will repeat each function as long as it succeeds, and then go
on to the next service action. */
- no_more = setup (getent_func_name, lookup_fct, (void **) &fct, nip,
+ no_more = setup (getent_func_name, lookup_fct, &fct.ptr, nip,
startp, 0);
while (! no_more)
{
int is_last_nip = *nip == *last_nip;
- status = DL_CALL_FCT (fct,
+ status = DL_CALL_FCT (fct.f,
(resbuf, buffer, buflen, &errno, &h_errno));
/* The the status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
@@ -168,7 +180,7 @@ __nss_getent_r (const char *getent_func_
do
{
- no_more = __nss_next (nip, getent_func_name, (void **) &fct,
+ no_more = __nss_next (nip, getent_func_name, &fct.ptr,
status, 0);
if (is_last_nip)
@@ -177,17 +189,21 @@ __nss_getent_r (const char *getent_func_
if (! no_more)
{
/* Call the `setXXent' function. This wasn't done before. */
- setent_function sfct;
+ union
+ {
+ setent_function f;
+ void *ptr;
+ } sfct;
no_more = __nss_lookup (nip, setent_func_name,
- (void **) &sfct);
+ &sfct.ptr);
if (! no_more)
{
if (stayopen_tmp)
- status = DL_CALL_FCT (sfct, (*stayopen_tmp));
+ status = DL_CALL_FCT (sfct.f, (*stayopen_tmp));
else
- status = DL_CALL_FCT (sfct, (0));
+ status = DL_CALL_FCT (sfct.f, (0));
}
else
status = NSS_STATUS_NOTFOUND;
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj
next prev parent reply other threads:[~2002-11-10 10:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-10 1:10 Andreas Jaeger
2002-11-10 2:18 ` Andreas Jaeger [this message]
2002-11-10 2:23 ` Ulrich Drepper
2002-11-10 3:05 ` Andreas Jaeger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=u8y9816842.fsf@gromit.moeb \
--to=aj@suse.de \
--cc=libc-hacker@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).