|
From: Bill S. <we...@ri...> - 2001-06-05 23:34:57
|
On Tue, 5 Jun 2001, Lars Christensen wrote: > Description: This patch fixes cast alignment bugs detected by using the > -Wcast-align option for gcc. Although > > *((DWORD*)&buffer[5]) = value; > > may work on an intel processor, it is not portable because some > architechtures (e.g. sparc) cannot copy DWORDS if they are not aligned on > a multiple of 4 bytes. The attached patch fixes all occurences of such > statements to: > > memcpy(buffer + 5, &value, sizeof(DWORD)); > > The patches is tested and icqlib works on Sparc Solaris with is (UDP > communication at least. TCP code is also changed, but untested - it does > compile though). icqlib would about with a "bus error" or "segmentation > fault" without this patch. Interesting - I never realized you have to worry about alignment. Why doesn't the compiler generate assembly code to just do the copy byte by byte? Any ideas? :) I'll apply the patch of course, just wondering for future reference. Bill |