Subject: Re: Build failure in ntpq.c
To: Julio M. Merino Vidal <jmmv84@gmail.com>
From: Frank Kardel <kardel@netbsd.org>
List: current-users
Date: 06/12/2006 12:46:26
Julio M. Merino Vidal wrote:

> Hi,
>
> [ CC'ing kardel@, who imported the latest ntp code ]
>
> I just got these build failures in current with sources as of a couple
> of hours ago:
>
> /usr/src/dist/ntp/ntpq/ntpq.c: In function `decodeint':
> /usr/src/dist/ntp/ntpq/ntpq.c:1935: warning: dereferencing type-punned
> pointer will break strict-aliasing rules
> /usr/src/dist/ntp/ntpq/ntpq.c:1936: warning: dereferencing type-punned
> pointer will break strict-aliasing rules
>
> /usr/src/dist/ntp/ntpq/ntpq_ops.c: In function `dogetassoc':
> /usr/src/dist/ntp/ntpq/ntpq_ops.c:880: warning: dereferencing
> type-punned pointer will break strict-aliasing rules
>
> The following fixed the problem.  Is it correct?

yepp - in short.

>
> Index: ntpq.c
> ===================================================================
> RCS file: /cvsroot/src/dist/ntp/ntpq/ntpq.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 ntpq.c
> --- ntpq.c    11 Jun 2006 19:34:21 -0000    1.8
> +++ ntpq.c    12 Jun 2006 09:59:51 -0000
> @@ -1932,8 +1932,8 @@ decodeint(
> {
>     if (*str == '0') {
>         if (*(str+1) == 'x' || *(str+1) == 'X')
> -            return hextoint(str+2, (u_long *)&val);
> -        return octtoint(str, (u_long *)&val);
> +            return hextoint(str+2, (u_long *)val);
> +        return octtoint(str, (u_long *)val);
>     }
>     return atoint(str, val);

> }

That code was really broken - need to  file a bug.

>
> Index: ntpq_ops.c
> ===================================================================
> RCS file: /cvsroot/src/dist/ntp/ntpq/ntpq_ops.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 ntpq_ops.c
> --- ntpq_ops.c    11 Jun 2006 19:34:21 -0000    1.4
> +++ ntpq_ops.c    12 Jun 2006 10:21:18 -0000
> @@ -871,13 +871,13 @@ dogetassoc(
>     FILE *fp
>     )
> {
> -    u_short *datap;
> +    char *datap;
>     int res;
>     int dsize;
>     u_short rstatus;
>
>     res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus,
> -              &dsize, (char **)&datap);
> +              &dsize, &datap);
>
>     if (res != 0)
>         return 0;
> @@ -900,9 +900,9 @@ dogetassoc(
>
>     numassoc = 0;
>     while (dsize > 0) {
> -        assoc_cache[numassoc].assid = ntohs(*datap);
> +        assoc_cache[numassoc].assid = ntohs(*((u_short *)datap));
>         datap++;
> -        assoc_cache[numassoc].status = ntohs(*datap);
> +        assoc_cache[numassoc].status = ntohs(*((u_short *)datap));
>         datap++;
>         if (++numassoc >= MAXASSOC)
>             break;
>
Alignment should be ok - static buffer of longs is the underlying.

> Thanks.
>
comitted