nano-malloc assumes sizeof(int) >= sizeof(void*)
DJ Delorie
dj@redhat.com
Tue Dec 16 03:42:00 GMT 2014
I don't know if there's a better (i.e. more portable) way of
aligning-up a pointer, but at least this moves the problem to
platforms where pointers are bigger than "long" instead of "int".
Found on msp430 large model, with the heap above the 64k boundary -
malloc() was truncating addresses to 16 bits. Ok?
* libc/stdlib/nano-mallocr.c (ALIGN_TO): Do not assume that
integers are as big as pointers.
Index: libc/stdlib/nano-mallocr.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/nano-mallocr.c,v
retrieving revision 1.3
diff -p -U 5 -r1.3 nano-mallocr.c
--- libc/stdlib/nano-mallocr.c 30 Oct 2013 15:53:05 -0000 1.3
+++ libc/stdlib/nano-mallocr.c 16 Dec 2014 03:34:45 -0000
@@ -103,11 +103,11 @@
#define free_list __malloc_free_list
#define sbrk_start __malloc_sbrk_start
#define current_mallinfo __malloc_current_mallinfo
#define ALIGN_TO(size, align) \
- (((size) + (align) -1) & ~((align) -1))
+ (((size) + (align) -1L) & ~((align) -1L))
/* Alignment of allocated block */
#define MALLOC_ALIGN (8U)
#define CHUNK_ALIGN (sizeof(void*))
#define MALLOC_PADDING ((MAX(MALLOC_ALIGN, CHUNK_ALIGN)) - CHUNK_ALIGN)
More information about the Newlib
mailing list