Skip to content

Commit 4155135

Browse files
Merge pull request #71 from scanoss/5.4.4
Solve bug with quality report breaking the json output. Minor improvements in snippet tolerance and ranges grouping.
2 parents 4c79d85 + 637a54c commit 4155135

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

inc/match_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#define SCAN_MAX_SNIPPETS_DEFAULT 1
7979
#define SCAN_MAX_COMPONENTS_DEFAULT 3
8080

81-
#define MATCH_LIST_TOLERANCE 0.996
81+
#define MATCH_LIST_TOLERANCE 98.5
8282
typedef struct match_data_t match_data_t; /* Forward declaration */
8383
typedef struct scan_data_t scan_data_t; /* Forward declaration*/
8484

inc/scanoss.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define WFP_REC_LN 18
4141

4242
/* Log files */
43-
#define SCANOSS_VERSION "5.4.3"
43+
#define SCANOSS_VERSION "5.4.4"
4444
#define SCAN_LOG "/tmp/scanoss_scan.log"
4545
#define MAP_DUMP "/tmp/scanoss_map.dump"
4646
#define SLOW_QUERY_LOG "/tmp/scanoss_slow_query.log"

src/help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Alternatively, these value can be written in %s\n\
8888
| 256 | Disable best match only (default: enabled) |\n\
8989
| 512 | Hide identified files (default: disabled) |\n\
9090
| 1024 | Enable download_url (default: disabled) |\n\
91-
| 2048 | Enable \"use path hint\" logic (default: disabled) |\n\
91+
| 2048 | Enable \"use path hint\" logic (default: disabled) |\n\
9292
| 4096 | Disable extended server stats (default: enabled) |\n\
9393
| 8192 | Disable health layer (default: enabled) |\n\
9494
| 16384 | Enable high accuracy, slower scan (default: disabled) |\n\

src/match_list.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ bool component_list_add_binary(component_list_t *list, component_data_t *new_com
210210
return false;
211211
}
212212

213+
bool tolerance_eval(int a, int b)
214+
{
215+
int relative_error = (abs(a - b) * 100) / ((a + b) / 2);
216+
if (100 - relative_error >= MATCH_LIST_TOLERANCE)
217+
return true;
218+
else
219+
return false;
220+
}
221+
213222

214223
/**
215224
* @brief Try to add a match in a existing matches list.
@@ -292,11 +301,11 @@ bool match_list_add(match_list_t *list, match_data_t *new_match, bool (*val)(mat
292301
}
293302
/* 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) */
294303
//TODO: this part of the code should be in the function pointer or I need to re-evaluate the archtecture of this function */
295-
if (list->autolimit && (list->headp.lh_first->match->hits * MATCH_LIST_TOLERANCE > list->last_element->match->hits))
304+
if (list->autolimit && !tolerance_eval(list->headp.lh_first->match->hits, list->last_element->match->hits))
296305
{
297306
np = list->headp.lh_first;
298307
/*We have to find and remove the unwanted elements */
299-
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)
308+
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)
300309
{
301310

302311
}

src/quality.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,11 @@ bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *d
7070

7171
string_clean(quality);
7272

73-
bool reported = false;
74-
7573
char result[MAX_FIELD_LN] = "\0";
7674
int len = 0;
7775

7876
if (*quality && (src < (sizeof(quality_sources) / sizeof(quality_sources[0]))))
7977
{
80-
if (iteration) len += sprintf(result+len,",");
8178
len += sprintf(result+len,"{");
8279
if (!src)
8380
{
@@ -88,16 +85,14 @@ bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *d
8885
len += sprintf(result+len,"\"score\": \"%s\",", quality);
8986
len += sprintf(result+len,"\"source\": \"%s\"", quality_sources[atoi(source)]);
9087
len += sprintf(result+len,"}");
91-
reported = true;
9288
match->quality_text = strdup(result);
93-
9489
}
9590

9691

9792
free(source);
9893
free(quality);
9994

100-
return reported;
95+
return true;
10196
}
10297

10398
/**

src/snippets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ matchmap_range * ranges_join_overlapping(matchmap_range *ranges, int size)
334334
matchmap_range *out_ranges = malloc(sizeof(matchmap_range) * MATCHMAP_RANGES);
335335

336336
int processed = 0;
337-
int tolerance = range_tolerance;
338-
while (processed < size)
337+
int tolerance = range_tolerance > 0 ? range_tolerance : 1;
338+
while (processed < size && tolerance < range_tolerance * 20)
339339
{
340340
int out_ranges_index = -1;
341341
processed = 0;

0 commit comments

Comments
 (0)