cherry-pick.FILE5_35-6-g2b6f3fbc.if-we-are-asked-to-print-annotations-and-there-are-no-annotations-in.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Subject: If we are asked to print annotations and there are no annotations in (...)
  2. Origin: FILE5_35-6-g2b6f3fbc <https://github.com/file/file/commit/FILE5_35-6-g2b6f3fbc>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Wed Oct 24 13:15:35 2018 +0000
  5. If we are asked to print annotations and there are no annotations in
  6. the matching entry, return 0 but break the search. This is handled
  7. by introducing 'found_match' and separating it's function from returnval.
  8. XXX: Nested entries.
  9. --- a/src/softmagic.c
  10. +++ b/src/softmagic.c
  11. @@ -171,11 +171,16 @@
  12. {
  13. uint32_t magindex = 0;
  14. unsigned int cont_level = 0;
  15. - int returnvalv = 0, e; /* if a match is found it is set to 1*/
  16. + int found_match = 0; /* if a match is found it is set to 1*/
  17. + int returnvalv = 0, e;
  18. int firstline = 1; /* a flag to print X\n X\n- X */
  19. struct buffer bb;
  20. int print = (ms->flags & MAGIC_NODESC) == 0;
  21. + /*
  22. + * returnval can be 0 if a match is found, but there was no
  23. + * annotation to be printed.
  24. + */
  25. if (returnval == NULL)
  26. returnval = &returnvalv;
  27. @@ -216,8 +221,10 @@
  28. flush = m->reln != '!';
  29. break;
  30. default:
  31. - if (m->type == FILE_INDIRECT)
  32. + if (m->type == FILE_INDIRECT) {
  33. + found_match = 1;
  34. *returnval = 1;
  35. + }
  36. switch (magiccheck(ms, m)) {
  37. case -1:
  38. @@ -239,6 +246,9 @@
  39. goto flush;
  40. }
  41. + if (*m->desc)
  42. + found_match = 1;
  43. +
  44. if ((e = handle_annotation(ms, m, firstline)) != 0)
  45. {
  46. *need_separator = 1;
  47. @@ -254,6 +264,7 @@
  48. if (print && *m->desc) {
  49. *need_separator = 1;
  50. *printed_something = 1;
  51. + *returnval = 1;
  52. if (print_sep(ms, firstline) == -1)
  53. return -1;
  54. if (mprint(ms, m) == -1)
  55. @@ -313,8 +324,10 @@
  56. flush = 1;
  57. break;
  58. default:
  59. - if (m->type == FILE_INDIRECT)
  60. + if (m->type == FILE_INDIRECT) {
  61. + found_match = 1;
  62. *returnval = 1;
  63. + }
  64. flush = 0;
  65. break;
  66. }
  67. @@ -339,6 +352,9 @@
  68. } else
  69. ms->c.li[cont_level].got_match = 1;
  70. + if (*m->desc)
  71. + found_match = 1;
  72. +
  73. if ((e = handle_annotation(ms, m, firstline))
  74. != 0) {
  75. *need_separator = 1;
  76. @@ -370,6 +386,7 @@
  77. if (file_printf(ms, " ") == -1)
  78. return -1;
  79. }
  80. + *returnval = 1;
  81. *need_separator = 0;
  82. if (mprint(ms, m) == -1)
  83. return -1;
  84. @@ -399,7 +416,6 @@
  85. }
  86. if (*printed_something) {
  87. firstline = 0;
  88. - *returnval = 1;
  89. }
  90. if ((ms->flags & MAGIC_CONTINUE) == 0 && *printed_something) {
  91. return *returnval; /* don't keep searching */