The mps_reserve macro uses the expression
(char *)(_mps_ap)->alloc + (_size) > (char *)(_mps_ap)->alloc
to detect if _size is so large that the addition overflows/wraps around. A similar expression is used in the BufferFill function:
AddrAdd(buffer->ap_s.alloc, size) < (Addr)buffer->ap_s.alloc
It seems that per the C standard, overflows for pointer arithmetic are undefined behavior. The attached file, when compiled with GCC 14, illustrates the problem.
It would probably be more portable to use unsigned arithmetic in this case.
The
mps_reservemacro uses the expressionto detect if
_sizeis so large that the addition overflows/wraps around. A similar expression is used in theBufferFillfunction:It seems that per the C standard, overflows for pointer arithmetic are undefined behavior. The attached file, when compiled with GCC 14, illustrates the problem.
It would probably be more portable to use unsigned arithmetic in this case.