Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern doesn't match #82

Open
hackoflpf opened this issue Jul 6, 2023 · 1 comment
Open

pattern doesn't match #82

hackoflpf opened this issue Jul 6, 2023 · 1 comment

Comments

@hackoflpf
Copy link

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 )

..
}

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;

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;
        }
@hackoflpf
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant