Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Problems with packages on a netbsd-6 sparc



At Wed, 2 May 2012 18:11:23 +0200, Martin Husemann 
<martin%duskware.de@localhost> wrote:
Subject: Re: Problems with packages on a netbsd-6 sparc
> 
> I had a look: as Eduardo suggested, the memcpy is inlined as a struct
> copy. The code is lying (by using bogus casts), and the compiler is
> correct in its optimization.
> 
> This patch avoids the lie about the memcpy() args to the compiler,
> but I have not tested it further:
> 
> --- pwutil.c.orig       2011-10-21 15:18:38.000000000 +0200
> +++ pwutil.c    2012-05-02 18:09:37.000000000 +0200
> @@ -174,8 +174,8 @@
>       * Copy in passwd contents and make strings relative to space
>       * at the end of the buffer.
>       */
> +    memcpy(cp, pw, sizeof(struct passwd));
>      newpw = (struct passwd *) cp;
> -    memcpy(newpw, pw, sizeof(struct passwd));
>      cp += sizeof(struct passwd);
>      FIELD_COPY(pw, newpw, pw_name, nsize);
>      FIELD_COPY(pw, newpw, pw_passwd, psize);

Why not avoid the non-intuitive memcpy() all together all the time and
just let the compiler do its job????

        newpw = pw;

C has allowed structure copies like this since at least C89, and much
earlier in many good compilers (the data pointed to by the fields which
are pointers still needs to be copied of course).

(of course the memory allocation hack there in sudo should be fixed too,
or maybe sudo should just be thrown in the trash and left there :-))

-- 
                                                Greg A. Woods
                                                Planix, Inc.

<woods%planix.com@localhost>       +1 250 762-7675        http://www.planix.com/

Attachment: pgp29VR0Vwd4m.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index