openbsd-ports/archivers/unrar/patches/patch-suballoc_cpp
pedro fba1c42a6c Fix crash due to unaligned memory access, enable some define options so
we can handle sizeof(off_t) and big endian architectures correctly.
Testing and input from Rui Reis <rui@rui.cx> (maintainer), okay jolan@
2006-01-24 00:02:07 +00:00

21 lines
537 B
Plaintext

$OpenBSD: patch-suballoc_cpp,v 1.1 2006/01/24 00:02:07 pedro Exp $
--- suballoc.cpp.orig Tue Oct 4 04:57:54 2005
+++ suballoc.cpp Sun Jan 22 18:21:03 2006
@@ -31,10 +31,16 @@ inline void* SubAllocator::RemoveNode(in
return RetVal;
}
+#define PAD __alignof__(void *)
+#define ROUND(v) ((v) & (PAD - 1) ? ((v) + PAD) & ~(PAD - 1) : (v))
inline uint SubAllocator::U2B(int NU)
{
+#ifndef __STRICT_ALIGNMENT
return /*8*NU+4*NU*/UNIT_SIZE*NU;
+#else
+ return (ROUND(UNIT_SIZE * NU));
+#endif /* !__STRICT_ALIGNMENT */
}