Zip problems (Re: (no subject))

Denys Duchier duchier at ps.uni-sb.de
Mon Nov 18 11:22:03 GMT 2002


david at mandrakesoft.com (David Faure) writes:

>> The fix is to change a memcpy by a qmemmove. However, I do not understand why 
>> it would be necessary in that case. (Gcc 3.2 bug?)
>
> From "man memcpy" :
> The memory areas may not overlap.  Use memmove(3) if the memory areas do overlap.
>
> This can be the only reason.

no, this is not the reason. the areas do not overlap.  however, there
is clearly a bug in gcc. when optimizing, it inlines memcpy for small
sized args, and screws up.  This can be easily checked with a simple
program:

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
  char* buffer = new char[8];
  const char head[] = {
    'A', 'B', 'C', 'D',
    'E', 'F', 'G', 'H'
  };
  asm("foo:");
  memcpy(buffer,head,sizeof(head));
  asm("baz:");
  for(int i=0;i<8;i++)
    cout << "[" << i << "] = " << head[i] << " , " << buffer[i] << endl;
  return 0;
}

when compiled with optimizations, this prints out the following for
me:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo
Type: application/octet-stream
Size: 94 bytes
Desc: output
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20021118/b3995b4c/attachment.obj>
-------------- next part --------------

I am going to ask on the gcc list about this.

Cheers,

PS: david, I am cc'ing to you as my email doesn't seem to make to the list

--Denys


More information about the kde-core-devel mailing list