[Top][All Lists]

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

Re: [PATCH 4/9] dfa: use a separate data type for grps

From: Paolo Bonzini
Subject: Re: [PATCH 4/9] dfa: use a separate data type for grps
Date: Tue, 03 Jan 2012 10:21:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0

On 01/03/2012 10:09 AM, Jim Meyering wrote:
>                  MALLOC(grps[ngrps].elems, d->nleaves);
>  -              copy(&grps[j],&grps[ngrps]);
>  +              memcpy(grps[ngrps].elems, grps[j].elems,
>  +                     grps[j].nelem * sizeof(unsigned int));
>  +              grps[ngrps].nelem = grps[j].nelem;
While slightly longer, the following is also slightly safer.
If the type of "elems" ever changes, we won't need to realize the
"sizeof(unsigned int)" above must also be changed to match that new type:

                  memcpy(grps[ngrps].elems, grps[j].elems,
                         grps[j].nelem * sizeof(*(grps[j].elems)));

Agreed, thanks!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]