@@ -248,10 +248,18 @@ _extract_source_from_buffer_location(GString *result, CfgIncludeLevel *level, co
248
248
249
249
if (lineno == yylloc -> first_line )
250
250
{
251
+ gint token_start = MIN (linelen , yylloc -> first_column - 1 );
252
+
251
253
if (yylloc -> first_line == yylloc -> last_line )
252
- g_string_append_len (result , & line [MIN (linelen , yylloc -> first_column - 1 )], yylloc -> last_column - yylloc -> first_column );
254
+ {
255
+ /* both last_column & first_column are 1 based, they cancel that out */
256
+ gint token_len = yylloc -> last_column - yylloc -> first_column ;
257
+ if (token_start + token_len > linelen )
258
+ token_len = linelen - token_start ;
259
+ g_string_append_len (result , & line [token_start ], token_len );
260
+ }
253
261
else
254
- g_string_append (result , & line [MIN ( linelen , yylloc -> first_column - 1 ) ]);
262
+ g_string_append (result , & line [token_start ]);
255
263
}
256
264
else if (lineno < yylloc -> last_line )
257
265
{
@@ -260,8 +268,12 @@ _extract_source_from_buffer_location(GString *result, CfgIncludeLevel *level, co
260
268
}
261
269
else if (lineno == yylloc -> last_line )
262
270
{
271
+ /* last_column is 1 based */
272
+ gint token_len = yylloc -> last_column - 1 ;
273
+ if (token_len > linelen )
274
+ token_len = linelen ;
263
275
g_string_append_c (result , ' ' );
264
- g_string_append_len (result , line , yylloc -> last_column );
276
+ g_string_append_len (result , line , token_len );
265
277
}
266
278
}
267
279
0 commit comments