On 03/29/2014 09:00 AM, 陈梁 wrote:

>>> You really need to do the "go over the rest" loop on an 8-byte temporary
>>> variable.  Ever since your patch made new_buf be a volatile buffer,
>>> rather than a static copy, you MUST visit each byte of new_buf exactly once.
>>>
>> hmm, thanks. get it. Maybe we can do it like this

> sorry, it should like this
> 
>         /* word at a time for speed */
>         if (!res) {
>             while (i < slen &&
>                    (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) {
>                 i += sizeof(long);
>                 zrun_len += sizeof(long);
>             }
> 
>             /* go over the rest */
>             //while (i < slen && old_buf[i] == new_buf[i]) {
>             //    zrun_len++;
>             //    i++;
>             //}
>         }

No, that's not right either.  Once you have made a decision based on
something you have read, you must proceed with that decision.  In the
case, you broke out of the while loop because you found a difference.
Now you must report the location of that difference, as of the time
where you read it and without re-reading from new_buf.  The ONLY viable
solution is to read the contents of new_buf into a temporary, then do
all subsequent actions on that temporary.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to