@@ -71,7 +71,7 @@ int makePromise (const char *parser,
7171 int r ;
7272 langType lang = LANG_IGNORE ;
7373
74- verbose ("makePromise: %s start(line: %lu, offset: %lu , srcline: %lu), end(line: %lu, offset: %lu )\n" ,
74+ verbose ("makePromise: %s start(line: %lu, offset: %ld , srcline: %lu), end(line: %lu, offset: %ld )\n" ,
7575 parser ? parser : "*" , startLine , startCharOffset , sourceLineOffset ,
7676 endLine , endCharOffset );
7777
@@ -197,7 +197,7 @@ int getLastPromise (void)
197197 return promise_count - 1 ;
198198}
199199
200- static unsigned char * fill_or_skip (unsigned char * input , unsigned char * input_end , bool filling )
200+ static unsigned char * fill_or_skip (unsigned char * input , const unsigned char * const input_end , const bool filling )
201201{
202202 if ( !(input < input_end ))
203203 return NULL ;
@@ -221,53 +221,59 @@ static unsigned char* fill_or_skip (unsigned char *input, unsigned char *input_e
221221 }
222222}
223223
224- static void line_filler (unsigned char * input , size_t size ,
225- unsigned long startLine , long startCharOffset ,
226- unsigned long endLine , long endCharOffset ,
224+ static void line_filler (unsigned char * input , size_t const size ,
225+ unsigned long const startLine , long const startCharOffset ,
226+ unsigned long const endLine , long const endCharOffset ,
227227 void * data )
228228{
229- ulongArray * lines = data ;
229+ const ulongArray * lines = data ;
230+ const size_t count = ulongArrayCount (lines );
230231 unsigned int start_index , end_index ;
231232 unsigned int i ;
232233
233- for (i = 0 ; i < ulongArrayCount ( lines ) ; i ++ )
234+ for (i = 0 ; i < count ; i ++ )
234235 {
235- unsigned long line = ulongArrayItem (lines , i );
236+ const unsigned long line = ulongArrayItem (lines , i );
236237 if (line >= startLine )
238+ {
239+ if (line > endLine )
240+ return ; /* Not over-wrapping */
237241 break ;
242+ }
238243 }
239- if (i == ulongArrayCount (lines ))
240- return ;
241- if (i > endLine )
242- return ;
244+ if (i == count )
245+ return ; /* Not over-wrapping */
243246 start_index = i ;
244247
245- for (; i < ulongArrayCount ( lines ) ; i ++ )
248+ for (; i < count ; i ++ )
246249 {
247- unsigned long line = ulongArrayItem (lines , i );
250+ const unsigned long line = ulongArrayItem (lines , i );
248251 if (line > endLine )
249252 break ;
250253 }
251254 end_index = i ;
252255
253256 unsigned long input_line = startLine ;
257+ const unsigned char * const input_end = input + size ;
254258 for (i = start_index ; i < end_index ; i ++ )
255259 {
256- unsigned long line = ulongArrayItem (lines , i );
260+ const unsigned long line = ulongArrayItem (lines , i );
257261
258262 while (1 )
259263 {
260264 if (input_line == line )
261265 {
262- input = fill_or_skip (input , input + size , true);
266+ input = fill_or_skip (input , input_end , true);
263267 input_line ++ ;
264268 break ;
265269 }
266270 else
267271 {
268- input = fill_or_skip (input , input + size , false);
272+ input = fill_or_skip (input , input_end , false);
269273 input_line ++ ;
270274 }
275+ if (input == NULL )
276+ return ;
271277 }
272278 }
273279}
0 commit comments