Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/scanoss.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define WFP_LN 4
#define WFP_REC_LN 18

#define SCANOSS_VERSION "6.0.1-crc64"
#define SCANOSS_VERSION "6.0.2-crc64"

/* Log files */
#define SCAN_LOG "/tmp/scanoss_scan.log"
Expand Down
16 changes: 15 additions & 1 deletion src/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ match_data_t * match_data_copy(match_data_t * in)
out->line_ranges = strdup(in->line_ranges);
out->oss_ranges = strdup(in->oss_ranges);
out->matched_percent = in->matched_percent;
out->lines_matched = in->lines_matched;
out->snippet_ids = strdup(in->snippet_ids);
out->scan_ower = in->scan_ower; /* keep owning scan so downstream (e.g. print_json_match) can deref it */
strcpy(out->source_md5, in->source_md5);
return out;
}
Expand Down Expand Up @@ -1099,6 +1101,18 @@ void match_select_best(scan_data_t *scan)
}
}

/**
* @brief Order multi-snippet matches by relevance (matched lines, descending).
* Used to rank the per-region candidates so the most-covered block is the
* principal match (match_index 0) and the rest follow as alternatives.
*/
bool more_lines_matched(match_data_t *a, match_data_t *b)
{
if (!a)
return true;
return (b->lines_matched > a->lines_matched);
}

match_list_t *match_select_m_component_best(scan_data_t *scan)
{
scanlog("<<<select_best_match_M: %d>>>>\n", scan->max_snippets_to_process);
Expand All @@ -1119,7 +1133,7 @@ match_list_t *match_select_m_component_best(scan_data_t *scan)
dup_match->component_list.match_ref = dup_match;
component_list_add(&dup_match->component_list, dup_comp, NULL, false);
dup_match->component_list.max_items = 1; // harcoded to show only fist component in report.
if (!match_list_add(final, dup_match, find_oldest_match, true))
if (!match_list_add(final, dup_match, more_lines_matched, true))
match_data_free(dup_match);
}

Expand Down
9 changes: 8 additions & 1 deletion src/purl_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,15 @@ static int snippet_scan_stream(FILE *in)
extract_csv(size_field, (char *) rec, 1, sizeof(size_field));
file_size = strtoull(size_field, NULL, 10);

/* snippet-scan is a multi-candidate discovery endpoint: it must expose
every non-overlapping snippet region, not just the single best block.
The engine-wide default (SCAN_MAX_SNIPPETS_DEFAULT = 1) would collapse
biggest_snippet() to one group, so unless the caller explicitly raised
-M we open it up to MAX_MULTIPLE_COMPONENTS groups. */
int snippet_max = scan_max_snippets > 1 ? scan_max_snippets : MAX_MULTIPLE_COMPONENTS;

scan = scan_data_init(file_path,
scan_max_snippets,
snippet_max,
scan_max_components,
scan_adjust_tolerance,
scan_ranking_threshold,
Expand Down
45 changes: 29 additions & 16 deletions src/snippet_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,41 @@ void biggest_snippet(scan_data_t *scan)
match_new->lines_matched = matched_lines;
//match_new->hits = hits;

do /*Check if there is already a list for this line ranges */
/* Place the match in the list of the snippet region it belongs to.
* First look for an existing list whose ranges intersect this match
* (same region -> alternative candidate). If none intersects, open a
* new list for this region while there is room; otherwise fall back to
* the last list. */
bool assigned = false;
for (i = 0; i < scan->matches_list_array_index; i++)
{
if (!scan->matches_list_array[scan->matches_list_array_index] && scan->matches_list_array_index < scan->max_snippets_to_process)
if (match_list_eval(scan->matches_list_array[i], match_new, ranges_intersection))
{
scan->matches_list_array[scan->matches_list_array_index] = match_list_init(true, 1); /*create the list if it doesnt exist*/
scan->matches_list_array_index++;
if(!match_list_add(scan->matches_list_array[i], match_new, hit_test, true))
{
match_data_free(match_new);
}
if (!match_list_add(scan->matches_list_array[i], match_new, hit_test, true))
match_data_free(match_new);
assigned = true;
break;
}
if (match_list_eval(scan->matches_list_array[i], match_new, ranges_intersection) || i == scan->max_snippets_to_process -1)
}

if (!assigned)
{
if (scan->matches_list_array_index < scan->max_snippets_to_process)
{
if(!match_list_add(scan->matches_list_array[i], match_new, hit_test, true))
{
match_data_free(match_new);
}
break;
/* New non-overlapping region: create its own list and add the match there */
int new_index = scan->matches_list_array_index;
scan->matches_list_array[new_index] = match_list_init(true, 1);
scan->matches_list_array_index++;
if (!match_list_add(scan->matches_list_array[new_index], match_new, hit_test, true))
match_data_free(match_new);
}
i++;
} while(i < scan->matches_list_array_index); /*Check if there is already a list for this line ranges */
else
{
/* No room left for new regions: force into the last list */
if (!match_list_add(scan->matches_list_array[scan->max_snippets_to_process - 1], match_new, hit_test, true))
match_data_free(match_new);
}
}
}
}
/*just for loging*/
Expand Down
110 changes: 110 additions & 0 deletions tests/snippet_multicomponent/main.c.wfp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
file=3bb103a46f94ed298d8c37b4a80d973c,9918,main.c
7=e795bac8
10=6e7bf056
14=16579738
25=23d6d030
28=d32e499d
30=09e0aecd,b7908937,21949e96
33=d400f39f
37=ef7d6cba,894d3fa4,2d1597e8
41=c848f202
44=be39f156
59=905e02fb
61=b7908937
67=18b3beaf
76=491ac1ea
81=06fbfde3
83=95c75ef3
84=d400f39f
88=b036ba15
95=c848f202,be39f156
111=c711d2e1
112=447c4417
114=9a106044,12ab20bb,0ce7ece1
115=151c9088,d434c84e,bac49cc6
116=2a6b8b81,1f38d8be
117=7001190b
119=25c9f85f,a6453c32,e9e65a61
120=4186b77b,ef9fe105
124=da55d5b9,b0924155
128=b378b9e0
129=addfb6b0
134=0dbb599f,ec33702f
135=80a48c6a
136=f4347ad7,d5fbdf3a
137=7ce444f8
139=137b0602,f12edbd6
142=3dd980ae,ac0b0110
144=a76b34a5
148=e0fa1c18,c741c7b2
151=193cc2c3
152=79eee8b8,b2e74c6e
156=7b280e25,d864c721
157=216caf87
158=a6a3bbe1,b66372cb
159=04ca6169,a7452328
162=75fa5176
163=d0cb6c6b,abafa52d
167=9396f071
168=30792053
169=4b7b9a0a
171=e6489ee3,8c952f0c
172=b9cded56
174=2d95465b
176=11781789
178=bd14a25f,f67df255
180=46491e29
183=c29128bc
184=5625dd8a,30792053
185=4b7b9a0a
187=dd6588d4,0a041ed0
188=341c8c04
189=e3cc063a
193=bea1b86c,802ddd80
196=f537a752,5218fbf7
198=f21eefbd
199=c2b9b9f9,9f6d2f6f
201=0724e239
203=1ec0629c
206=8dbf6363
207=771caaeb
212=35ac838c
214=f94d5b4c,a169fcbf
216=4e6c1cbe
217=4666a13c
219=077eccf8
222=0ae64d50
224=9712f0ff,4d24ea64
228=78ef004d,46c56394,07bc7452
230=97b52f82
232=e3af2023
236=161a335f
237=f6a61105
241=273539a2,08dcf25a,ac7340d8
246=d0c75748
248=061baf8c
250=f941efa7
253=36d3594e
255=af8cf5fb,40b333f4
259=8b1ff8bf,6cf0d5ac
260=b803e9eb
264=3cc8ad46
265=74d8a41f
269=0547b4df,b846d5c2
272=3926ed53,4bf276e9,29af2a76
274=fdb2863f,6b99be79
275=6bc888a0
278=05bf9646
281=48848bae
284=4d6fcc13
285=cfc7ff90
288=ab7fc8cd,fb85472f
291=64f5cde0,0d2eca0b
292=791fbabd
296=07cfc5fe
297=357fa0d4,87642ec3
299=16e81aa2
301=0acd0d5d,085f6061,c727d6af
303=ac932df0
306=0698ae44
308=3dbbeabb,5919152f
Loading
Loading