Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#484 closed bug (fixed)

omalloc alignment detection should use volatile pointers

Reported by: jdemeyer@… 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 Changed 11 years ago by hannes

Resolution: fixed
Status: newclosed

Thanks for the report. 1.1 should always (with the same compiler) give the same representations, but 1.25 should also work.

comment:2 in reply to:  1 Changed 11 years ago by jdemeyer@…

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.