summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-10-07 19:29:18 +0000
committerThomas Martitz <kugel@rockbox.org>2011-10-07 19:29:18 +0000
commit5783505b99eeb53c271d2437153a5e4a7f278d4d (patch)
tree79033b5d423d5a0cbc3dcce4ce0e8aa423b124c7
parent42a33a7f70de01b64e2430dc1c989a2937126818 (diff)
downloadrockbox-5783505b99eeb53c271d2437153a5e4a7f278d4d.zip
rockbox-5783505b99eeb53c271d2437153a5e4a7f278d4d.tar.gz
rockbox-5783505b99eeb53c271d2437153a5e4a7f278d4d.tar.bz2
rockbox-5783505b99eeb53c271d2437153a5e4a7f278d4d.tar.xz
Add two macros for char*-based pointer arithmetic and use it in font.c
This fixes errornous pointer addition (+ on a short*), which crashed in some situation. Fixes FS#12317 and should hopefully get the clips booting again. Thanks to Jonathan Gordon for spotting the bad pointer arithmetic. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30724 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/system.h2
-rw-r--r--firmware/font.c29
2 files changed, 15 insertions, 16 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h
index cec47f1..aa07994 100644
--- a/firmware/export/system.h
+++ b/firmware/export/system.h
@@ -124,6 +124,8 @@ int get_cpu_boost_counter(void);
ptr = (typeof(ptr))tmp_ptr1; \
}
+#define PTR_ADD(ptr, x) ((typeof(ptr))((char*)(ptr) + (x)))
+#define PTR_SUB(ptr, x) ((typeof(ptr))((char*)(ptr) - (x)))
/* newer? SDL includes endian.h, So we ignore it */
#if (CONFIG_PLATFORM & PLATFORM_HOSTED) || defined(__PCTOOL__)
diff --git a/firmware/font.c b/firmware/font.c
index 0546061..8cd9be1 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -88,26 +88,23 @@ static int buflibmove_callback(int handle, void* current, void* new)
{
(void)handle;
struct buflib_alloc_data *alloc = (struct buflib_alloc_data*)current;
- size_t diff = new - current;
+ ptrdiff_t diff = new - current;
if (alloc->handle_locked)
return BUFLIB_CB_CANNOT_MOVE;
- if (alloc->font.bits)
- alloc->font.bits += diff;
- if (alloc->font.offset)
- alloc->font.offset += diff;
- if (alloc->font.width)
- alloc->font.width += diff;
-
- alloc->font.buffer_start += diff;
- alloc->font.buffer_end += diff;
- alloc->font.buffer_position += diff;
-
- if (alloc->font.cache._index)
- alloc->font.cache._index += diff;
- if (alloc->font.cache._lru._base)
- alloc->font.cache._lru._base += diff;
+#define UPDATE(x) if (x) { x = PTR_ADD(x, diff); }
+
+ UPDATE(alloc->font.bits);
+ UPDATE(alloc->font.offset);
+ UPDATE(alloc->font.width);
+
+ UPDATE(alloc->font.buffer_start);
+ UPDATE(alloc->font.buffer_end);
+ UPDATE(alloc->font.buffer_position);
+
+ UPDATE(alloc->font.cache._index);
+ UPDATE(alloc->font.cache._lru._base);
return BUFLIB_CB_OK;
}