Subject: If we are asked to print annotations and there are no annotations in (...) Origin: FILE5_35-6-g2b6f3fbc Upstream-Author: Christos Zoulas Date: Wed Oct 24 13:15:35 2018 +0000 If we are asked to print annotations and there are no annotations in the matching entry, return 0 but break the search. This is handled by introducing 'found_match' and separating it's function from returnval. XXX: Nested entries. --- a/src/softmagic.c +++ b/src/softmagic.c @@ -171,11 +171,16 @@ { uint32_t magindex = 0; unsigned int cont_level = 0; - int returnvalv = 0, e; /* if a match is found it is set to 1*/ + int found_match = 0; /* if a match is found it is set to 1*/ + int returnvalv = 0, e; int firstline = 1; /* a flag to print X\n X\n- X */ struct buffer bb; int print = (ms->flags & MAGIC_NODESC) == 0; + /* + * returnval can be 0 if a match is found, but there was no + * annotation to be printed. + */ if (returnval == NULL) returnval = &returnvalv; @@ -216,8 +221,10 @@ flush = m->reln != '!'; break; default: - if (m->type == FILE_INDIRECT) + if (m->type == FILE_INDIRECT) { + found_match = 1; *returnval = 1; + } switch (magiccheck(ms, m)) { case -1: @@ -239,6 +246,9 @@ goto flush; } + if (*m->desc) + found_match = 1; + if ((e = handle_annotation(ms, m, firstline)) != 0) { *need_separator = 1; @@ -254,6 +264,7 @@ if (print && *m->desc) { *need_separator = 1; *printed_something = 1; + *returnval = 1; if (print_sep(ms, firstline) == -1) return -1; if (mprint(ms, m) == -1) @@ -313,8 +324,10 @@ flush = 1; break; default: - if (m->type == FILE_INDIRECT) + if (m->type == FILE_INDIRECT) { + found_match = 1; *returnval = 1; + } flush = 0; break; } @@ -339,6 +352,9 @@ } else ms->c.li[cont_level].got_match = 1; + if (*m->desc) + found_match = 1; + if ((e = handle_annotation(ms, m, firstline)) != 0) { *need_separator = 1; @@ -370,6 +386,7 @@ if (file_printf(ms, " ") == -1) return -1; } + *returnval = 1; *need_separator = 0; if (mprint(ms, m) == -1) return -1; @@ -399,7 +416,6 @@ } if (*printed_something) { firstline = 0; - *returnval = 1; } if ((ms->flags & MAGIC_CONTINUE) == 0 && *printed_something) { return *returnval; /* don't keep searching */