Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix up font_cache/LRU boundry errors from r30763

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31050 a1c6a512-1295-4272-9138-f99709370657

+35 -17
+35 -17
firmware/font_cache.c
··· 78 78 ************************************************************************/ 79 79 static int search(struct font_cache* fcache, 80 80 unsigned short char_code, 81 + int size, 81 82 int *p_insertion_point ) 82 83 { 83 84 struct font_cache_entry *p; 84 85 int left, right, mid=-1, c; 85 86 left = 0; 86 - right = fcache->_size - 1; 87 - 87 + right = size; 88 + 88 89 /* go for a lucky guess */ 89 90 mid = char_code + 90 91 fcache->_prev_result - fcache->_prev_char_code; ··· 115 116 while (left <= right); 116 117 117 118 /* not found */ 119 + p = lru_data(&fcache->_lru, fcache->_index[mid]); 118 120 *p_insertion_point = mid; 119 121 return 0; 120 122 } ··· 131 133 int insertion_point; 132 134 int index_to_replace; 133 135 134 - if( search(fcache, char_code, &insertion_point)) 136 + /* check bounds */ 137 + p = lru_data(&fcache->_lru, fcache->_index[0]); 138 + if( char_code < p->_char_code ) 139 + insertion_point = -1; 140 + else 135 141 { 136 - short lru_handle = fcache->_index[insertion_point]; 137 - p = lru_data(&fcache->_lru, lru_handle); 138 - if (p->_char_code == char_code) 142 + p = lru_data(&fcache->_lru, fcache->_index[fcache->_capacity - 1]); 143 + if( char_code > p->_char_code ) 139 144 { 140 - lru_touch(&fcache->_lru, lru_handle); 141 - return lru_data(&fcache->_lru, lru_handle); 145 + insertion_point = fcache->_capacity - 1; 142 146 } 143 - } 144 - else /* not found */ 145 - { 146 - p = lru_data(&fcache->_lru, 147 - fcache->_index[insertion_point+1]); 148 - if ( char_code > p->_char_code ) 149 - insertion_point++; 147 + else 148 + { 149 + if( search(fcache, char_code, fcache->_size - 1, &insertion_point)) 150 + { 151 + short lru_handle = fcache->_index[insertion_point]; 152 + p = lru_data(&fcache->_lru, lru_handle); 153 + if (p->_char_code == char_code) 154 + { 155 + lru_touch(&fcache->_lru, lru_handle); 156 + return lru_data(&fcache->_lru, lru_handle); 157 + } 158 + } 159 + else 160 + { 161 + p = lru_data(&fcache->_lru, 162 + fcache->_index[insertion_point+1]); 163 + if ( char_code > p->_char_code ) 164 + insertion_point++; 165 + } 166 + } 150 167 } 168 + 169 + /* not found */ 151 170 152 171 /* find index to replace */ 153 172 short lru_handle_to_replace = fcache->_lru._head; 154 173 p = lru_data(&fcache->_lru, lru_handle_to_replace); 155 - search(fcache, p->_char_code, &index_to_replace); 156 - 174 + search(fcache, p->_char_code, fcache->_size - 1, &index_to_replace); 157 175 if (insertion_point < index_to_replace) 158 176 { 159 177 /* shift memory up */