From 2caf8870afd844c1368d21b98b3d1e4c0ee8bf10 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 20 Dec 2014 12:55:20 +0100 Subject: text_viewer plugin: Fix two out-of-bounds buffer accesses Test code: -------------- int main(void) { static unsigned short extra_spaces[] = { 0, 0x3000 }; return sizeof(extra_spaces); } -------------- -> returns four instead of two. cppcheck reported: [rockbox/apps/plugins/text_viewer/tv_text_processor.c:180]: (error) Array 'break_chars[27]' acces sed at index 53, which is out of bounds. [rockbox/apps/plugins/text_viewer/tv_text_processor.c:195]: (error) Array 'extra_spaces[2]' acces sed at index 3, which is out of bounds. Change-Id: I66c305cc5c99e59e7c8e0aa9c86cecbe293ff037 --- apps/plugins/text_viewer/tv_text_processor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/plugins/text_viewer/tv_text_processor.c b/apps/plugins/text_viewer/tv_text_processor.c index d027a9a13a..fa644d7725 100644 --- a/apps/plugins/text_viewer/tv_text_processor.c +++ b/apps/plugins/text_viewer/tv_text_processor.c @@ -175,7 +175,7 @@ static bool tv_is_line_break_char(unsigned short ch) if (preferences->word_mode == WM_CHOP) return false; - for (i = 0; i < sizeof(break_chars); i++) + for (i = 0; i < sizeof(break_chars)/sizeof(unsigned short); i++) { if (break_chars[i] == ch) return true; @@ -190,7 +190,7 @@ static bool tv_isspace(unsigned short ch) if (ch < 128 && isspace(ch)) return true; - for (i = 0; i < sizeof(extra_spaces); i++) + for (i = 0; i < sizeof(extra_spaces)/sizeof(unsigned short); i++) { if (extra_spaces[i] == ch) return true; -- cgit v1.2.3