#484 closed bug (fixed)
omalloc alignment detection should use volatile pointers
Reported by: | Owned by: | somebody | |
---|---|---|---|
Priority: | minor | Milestone: | 3-2-0 and higher |
Component: | omalloc | Version: | 3-1-6 |
Keywords: | Cc: |
Description
omalloc/configure
has the following code snippet to check for "strict" alignment (whatever that means):
main() { void* ptr = (void*) malloc(12); double* d_ptr; if ((unsigned long) ptr % 8 == 0) ptr = ptr + 4; d_ptr = (double*) ptr; *d_ptr = (double) 1.1; if (*d_ptr != (double) 1.1) exit(1); else exit(0); }
However, the compiler might optimize away the memory access to d_ptr
, such that nothing really is checked. Solution: use
volatile double* d_ptr;
Besides that, I also think it is dangerous to use the constant 1.1
which cannot be exactly represented as a double. A value like 1.25
would be safer.
Change History (2)
comment:1 follow-up: 2 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
Replying to hannes:
1.1 should always (with the same compiler) give the same representations
Are you sure? I wouldn't bet on it, in case a double rounding happens.
Note: See
TracTickets for help on using
tickets.
Thanks for the report. 1.1 should always (with the same compiler) give the same representations, but 1.25 should also work.