Theodore Tso <[EMAIL PROTECTED]> writes: > On Mon, Nov 13, 2006 at 09:49:21AM +0100, Falk Hueffner wrote: >> Hi, >> >> this looks like an aliasing violation to me. bb->list, which is of >> type __u32*, is accessed via an lvalue of type void*, which is not >> compatible. Does the problem go away with -fno-strict-aliasing? > > Good point, thanks. Yes, it does go away when I use > -fno-strict-aliasing. > > Interestingly, I didn't get nary a peep when I enabled tried running > gcc "-O2 -Wstrict-aliasing=2". I would have expected gcc to have > complained about this, but apparently not. > > Do you think the problem is with the call to ext2fs_get_mem: > > retval = ext2fs_get_mem(bb->size * sizeof(blk_t), &bb->list); > > where I pass a __u32* to ext2fs_get_mem as a void*? > > > Or the implementation where I play games with void** and void*: > > _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) > { > void **pp = (void **)ptr; > > *pp = malloc(size); > ...
Well, neither. All the intermediary types of pointers don't matter; the actual problem is at the access of bb->list via an lvalue of a bad type. > I tried changing the function signature of ext2fs_get_mem() to be: > > _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, char *ptr) > > ... since according to the spec storing through a char* is supposed to > be OK, but that didn't seem to fix the problem. How did you do it exactly? For example memcpy() should work. > I'd really hate to be forced to change the function signature to > something like this: > > _INLINE_ void * ext2fs_get_mem2(unsigned long size, errcode_t *retval) > > just to get around these [EMAIL PROTECTED] type-punning rules, but I can't > think of > anything else that might work. Is there anything you might suggest? Well, if you really want to retain the signature, I cannot think of anything better than using memcpy. -- Falk -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]