weggli is a fast and robust semantic search tool for C and C++ codebases. It is designed to help security researchers identify interesting functionality in large codebases.
searcch pattern is :
weggli '$a = 0;
NOT: if($a);
_ / $a;' ./src/autofit/aflatin.c -v,i add not search if($a),but it still match,i don't known how to debug this question.
04:37:46 [INFO] normalizing query: add {}
04:37:46 [INFO] query sexp: (translation_unit (compound_statement (expression_statement (assignment_expression left: (identifier) right: (number_literal))) (labeled_statement label: (statement_identifier) (if_statement condition: (parenthesized_expression (identifier)) consequence: (expression_statement))) (expression_statement (binary_expression left: (identifier) right: (identifier)))))
04:37:46 [INFO] parsing 1 files
/home/admins/freetypes_fuzzing/freetype-2.10.1/./src/autofit/aflatin.c:1965
FT_LOCAL_DEF( void )
af_latin_hints_link_segments( AF_GlyphHints hints,
..
if ( width_count )
max_width = widths[width_count - 1].org;
else
max_width = 0;
/* a heuristic value to set up a minimum value for overlapping */
len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
if ( len_threshold == 0 )
len_threshold = 1;
..
if ( max_width )
{
/* distance demerits are based on multiples of `max_width'; */
/* we scale by 1024 for getting more precision */
FT_Pos delta = ( dist << 10 ) / max_width - ( 1 << 10 );
if ( delta > 10000 )
dist_demerit = 32000;
else if ( delta > 0 )
if ( width_count )
max_width = widths[width_count - 1].org;
else
max_width = 0;
/* a heuristic value to set up a minimum value for overlapping */
len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
if ( len_threshold == 0 )
len_threshold = 1;
/* a heuristic value to weight lengths */
len_score = AF_LATIN_CONSTANT( hints->metrics, 6000 );
/* a heuristic value to weight distances (no call to */
/* AF_LATIN_CONSTANT needed, since we work on multiples */
/* of the stem width) */
dist_score = 3000;
/* now compare each segment to the others */
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
if ( seg1->dir != axis->major_dir )
continue;
/* search for stems having opposite directions, */
/* with seg1 to the `left' of seg2 */
for ( seg2 = segments; seg2 < segment_limit; seg2++ )
{
FT_Pos pos1 = seg1->pos;
FT_Pos pos2 = seg2->pos;
if ( seg1->dir + seg2->dir == 0 && pos2 > pos1 )
{
/* compute distance between the two segments */
FT_Pos min = seg1->min_coord;
FT_Pos max = seg1->max_coord;
FT_Pos len;
if ( min < seg2->min_coord )
min = seg2->min_coord;
if ( max > seg2->max_coord )
max = seg2->max_coord;
/* compute maximum coordinate difference of the two segments */
/* (this is, how much they overlap) */
len = max - min;
if ( len >= len_threshold )
{
/*
* The score is the sum of two demerits indicating the
* `badness' of a fit, measured along the segments' main axis
* and orthogonal to it, respectively.
*
* - The less overlapping along the main axis, the worse it
* is, causing a larger demerit.
*
* - The nearer the orthogonal distance to a stem width, the
* better it is, causing a smaller demerit. For simplicity,
* however, we only increase the demerit for values that
* exceed the largest stem width.
*/
FT_Pos dist = pos2 - pos1;
FT_Pos dist_demerit, score;
if ( max_width )
{
/* distance demerits are based on multiples of `max_width'; */
/* we scale by 1024 for getting more precision */
FT_Pos delta = ( dist << 10 ) / max_width - ( 1 << 10 );
if ( delta > 10000 )
dist_demerit = 32000;
else if ( delta > 0 )
dist_demerit = delta * delta / dist_score;
else
dist_demerit = 0;
}
searcch pattern is : weggli '$a = 0; NOT: if($a); _ / $a;' ./src/autofit/aflatin.c -v,i add not search if($a),but it still match,i don't known how to debug this question. 04:37:46 [INFO] normalizing query: add {} 04:37:46 [INFO] query sexp: (translation_unit (compound_statement (expression_statement (assignment_expression left: (identifier) right: (number_literal))) (labeled_statement label: (statement_identifier) (if_statement condition: (parenthesized_expression (identifier)) consequence: (expression_statement))) (expression_statement (binary_expression left: (identifier) right: (identifier))))) 04:37:46 [INFO] parsing 1 files /home/admins/freetypes_fuzzing/freetype-2.10.1/./src/autofit/aflatin.c:1965 FT_LOCAL_DEF( void ) af_latin_hints_link_segments( AF_GlyphHints hints, ..
..
.. }
source code is : FT_LOCAL_DEF( void ) af_latin_hints_link_segments( AF_GlyphHints hints, FT_UInt width_count, AF_WidthRec* widths, AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; AF_Segment segments = axis->segments; AF_Segment segment_limit = segments + axis->num_segments; FT_Pos len_threshold, len_score, dist_score, max_width; AF_Segment seg1, seg2;