Skip to content

Commit

Permalink
Merge pull request #71 from scanoss/5.4.4
Browse files Browse the repository at this point in the history
Solve bug with quality report breaking the json output. Minor improvements in snippet tolerance and ranges grouping.
  • Loading branch information
mscasso-scanoss authored Apr 25, 2024
2 parents 4c79d85 + 637a54c commit 4155135
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion inc/match_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
#define SCAN_MAX_SNIPPETS_DEFAULT 1
#define SCAN_MAX_COMPONENTS_DEFAULT 3

#define MATCH_LIST_TOLERANCE 0.996
#define MATCH_LIST_TOLERANCE 98.5
typedef struct match_data_t match_data_t; /* Forward declaration */
typedef struct scan_data_t scan_data_t; /* Forward declaration*/

Expand Down
2 changes: 1 addition & 1 deletion inc/scanoss.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define WFP_REC_LN 18

/* Log files */
#define SCANOSS_VERSION "5.4.3"
#define SCANOSS_VERSION "5.4.4"
#define SCAN_LOG "/tmp/scanoss_scan.log"
#define MAP_DUMP "/tmp/scanoss_map.dump"
#define SLOW_QUERY_LOG "/tmp/scanoss_slow_query.log"
Expand Down
2 changes: 1 addition & 1 deletion src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Alternatively, these value can be written in %s\n\
| 256 | Disable best match only (default: enabled) |\n\
| 512 | Hide identified files (default: disabled) |\n\
| 1024 | Enable download_url (default: disabled) |\n\
| 2048 | Enable \"use path hint\" logic (default: disabled) |\n\
| 2048 | Enable \"use path hint\" logic (default: disabled) |\n\
| 4096 | Disable extended server stats (default: enabled) |\n\
| 8192 | Disable health layer (default: enabled) |\n\
| 16384 | Enable high accuracy, slower scan (default: disabled) |\n\
Expand Down
13 changes: 11 additions & 2 deletions src/match_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ bool component_list_add_binary(component_list_t *list, component_data_t *new_com
return false;
}

bool tolerance_eval(int a, int b)
{
int relative_error = (abs(a - b) * 100) / ((a + b) / 2);
if (100 - relative_error >= MATCH_LIST_TOLERANCE)
return true;
else
return false;
}


/**
* @brief Try to add a match in a existing matches list.
Expand Down Expand Up @@ -292,11 +301,11 @@ bool match_list_add(match_list_t *list, match_data_t *new_match, bool (*val)(mat
}
/* in autolimit mode the list doesnt have a fix size, it will accept all the matchest until a 75% of the fist element (the biggest) */
//TODO: this part of the code should be in the function pointer or I need to re-evaluate the archtecture of this function */
if (list->autolimit && (list->headp.lh_first->match->hits * MATCH_LIST_TOLERANCE > list->last_element->match->hits))
if (list->autolimit && !tolerance_eval(list->headp.lh_first->match->hits, list->last_element->match->hits))
{
np = list->headp.lh_first;
/*We have to find and remove the unwanted elements */
for (; np->entries.le_next != NULL && (list->headp.lh_first->match->hits * MATCH_LIST_TOLERANCE <= np->entries.le_next->match->hits); np = np->entries.le_next)
for (; np->entries.le_next != NULL && tolerance_eval(list->headp.lh_first->match->hits, np->entries.le_next->match->hits); np = np->entries.le_next)
{

}
Expand Down
7 changes: 1 addition & 6 deletions src/quality.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *d

string_clean(quality);

bool reported = false;

char result[MAX_FIELD_LN] = "\0";
int len = 0;

if (*quality && (src < (sizeof(quality_sources) / sizeof(quality_sources[0]))))
{
if (iteration) len += sprintf(result+len,",");
len += sprintf(result+len,"{");
if (!src)
{
Expand All @@ -88,16 +85,14 @@ bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *d
len += sprintf(result+len,"\"score\": \"%s\",", quality);
len += sprintf(result+len,"\"source\": \"%s\"", quality_sources[atoi(source)]);
len += sprintf(result+len,"}");
reported = true;
match->quality_text = strdup(result);

}


free(source);
free(quality);

return reported;
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/snippets.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ matchmap_range * ranges_join_overlapping(matchmap_range *ranges, int size)
matchmap_range *out_ranges = malloc(sizeof(matchmap_range) * MATCHMAP_RANGES);

int processed = 0;
int tolerance = range_tolerance;
while (processed < size)
int tolerance = range_tolerance > 0 ? range_tolerance : 1;
while (processed < size && tolerance < range_tolerance * 20)
{
int out_ranges_index = -1;
processed = 0;
Expand Down

0 comments on commit 4155135

Please sign in to comment.