1665324403.FILE5_43-63-g3503cc0c.maintain-firstline-correctly.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. Subject: Maintain firstline correctly
  2. Origin: FILE5_43-63-g3503cc0c <https://github.com/file/file/commit/FILE5_43-63-g3503cc0c>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Sun Oct 9 14:06:43 2022 +0000
  5. --- a/src/softmagic.c
  6. +++ b/src/softmagic.c
  7. @@ -45,11 +45,11 @@
  8. private int match(struct magic_set *, struct magic *, file_regex_t **, size_t,
  9. const struct buffer *, size_t, int, int, int, uint16_t *,
  10. - uint16_t *, int *, int *, int *, int *);
  11. + uint16_t *, int *, int *, int *, int *, int *);
  12. private int mget(struct magic_set *, struct magic *, const struct buffer *,
  13. const unsigned char *, size_t,
  14. size_t, unsigned int, int, int, int, uint16_t *,
  15. - uint16_t *, int *, int *, int *, int *);
  16. + uint16_t *, int *, int *, int *, int *, int *);
  17. private int msetoffset(struct magic_set *, struct magic *, struct buffer *,
  18. const struct buffer *, size_t, unsigned int);
  19. private int magiccheck(struct magic_set *, struct magic *, file_regex_t **);
  20. @@ -118,7 +118,7 @@
  21. uint16_t *indir_count, uint16_t *name_count, int mode, int text)
  22. {
  23. struct mlist *ml;
  24. - int rv = 0, printed_something = 0, need_separator = 0;
  25. + int rv = 0, printed_something = 0, need_separator = 0, firstline = 1;
  26. uint16_t nc, ic;
  27. if (name_count == NULL) {
  28. @@ -133,7 +133,8 @@
  29. for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next) {
  30. int ret = match(ms, ml->magic, ml->magic_rxcomp, ml->nmagic, b,
  31. 0, mode, text, 0, indir_count, name_count,
  32. - &printed_something, &need_separator, NULL, NULL);
  33. + &printed_something, &need_separator, &firstline,
  34. + NULL, NULL);
  35. switch (ret) {
  36. case -1:
  37. return ret;
  38. @@ -205,15 +206,13 @@
  39. match(struct magic_set *ms, struct magic *magic, file_regex_t **magic_rxcomp,
  40. size_t nmagic, const struct buffer *b, size_t offset, int mode, int text,
  41. int flip, uint16_t *indir_count, uint16_t *name_count,
  42. - int *printed_something, int *need_separator, int *returnval,
  43. - int *found_match)
  44. + int *printed_something, int *need_separator, int *firstline,
  45. + int *returnval, int *found_match)
  46. {
  47. uint32_t magindex = 0;
  48. unsigned int cont_level = 0;
  49. int found_matchv = 0; /* if a match is found it is set to 1*/
  50. int returnvalv = 0, e;
  51. - /* a flag to print X\n X\n- X */
  52. - int firstline = !(*printed_something || *need_separator);
  53. struct buffer bb;
  54. int print = (ms->flags & MAGIC_NODESC) == 0;
  55. @@ -257,7 +256,8 @@
  56. switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf),
  57. bb.flen, offset, cont_level,
  58. mode, text, flip, indir_count, name_count,
  59. - printed_something, need_separator, returnval, found_match))
  60. + printed_something, need_separator, firstline, returnval,
  61. + found_match))
  62. {
  63. case -1:
  64. return -1;
  65. @@ -290,7 +290,7 @@
  66. goto flush;
  67. }
  68. - if ((e = handle_annotation(ms, m, firstline)) != 0)
  69. + if ((e = handle_annotation(ms, m, *firstline)) != 0)
  70. {
  71. *found_match = 1;
  72. *need_separator = 1;
  73. @@ -309,7 +309,7 @@
  74. *returnval = 1;
  75. *need_separator = 1;
  76. *printed_something = 1;
  77. - if (print_sep(ms, firstline) == -1)
  78. + if (print_sep(ms, *firstline) == -1)
  79. return -1;
  80. if (mprint(ms, m) == -1)
  81. return -1;
  82. @@ -368,7 +368,7 @@
  83. bb.fbuf), bb.flen, offset,
  84. cont_level, mode, text, flip, indir_count,
  85. name_count, printed_something, need_separator,
  86. - returnval, found_match)) {
  87. + firstline, returnval, found_match)) {
  88. case -1:
  89. return -1;
  90. case 0:
  91. @@ -405,7 +405,7 @@
  92. } else
  93. ms->c.li[cont_level].got_match = 1;
  94. - if ((e = handle_annotation(ms, m, firstline))
  95. + if ((e = handle_annotation(ms, m, *firstline))
  96. != 0) {
  97. *found_match = 1;
  98. *need_separator = 1;
  99. @@ -431,7 +431,7 @@
  100. */
  101. if (!*printed_something) {
  102. *printed_something = 1;
  103. - if (print_sep(ms, firstline)
  104. + if (print_sep(ms, *firstline)
  105. == -1)
  106. return -1;
  107. }
  108. @@ -467,14 +467,14 @@
  109. }
  110. }
  111. if (*printed_something) {
  112. - firstline = 0;
  113. + *firstline = 0;
  114. }
  115. if (*found_match) {
  116. if ((ms->flags & MAGIC_CONTINUE) == 0)
  117. return *returnval;
  118. // So that we print a separator
  119. *printed_something = 0;
  120. - firstline = 0;
  121. + *firstline = 0;
  122. }
  123. cont_level = 0;
  124. }
  125. @@ -1564,7 +1564,7 @@
  126. mget(struct magic_set *ms, struct magic *m, const struct buffer *b,
  127. const unsigned char *s, size_t nbytes, size_t o, unsigned int cont_level,
  128. int mode, int text, int flip, uint16_t *indir_count, uint16_t *name_count,
  129. - int *printed_something, int *need_separator, int *returnval,
  130. + int *printed_something, int *need_separator, int *firstline, int *returnval,
  131. int *found_match)
  132. {
  133. uint32_t eoffset, offset = ms->offset;
  134. @@ -1860,15 +1860,11 @@
  135. for (mlp = ms->mlist[0]->next; mlp != ms->mlist[0];
  136. mlp = mlp->next)
  137. {
  138. - int xprinted_something = 0;
  139. - int xneed_separator = 0;
  140. if ((rv = match(ms, mlp->magic, mlp->magic_rxcomp,
  141. mlp->nmagic, &bb, 0, BINTEST, text, 0, indir_count,
  142. - name_count, &xprinted_something, &xneed_separator,
  143. - NULL, NULL)) != 0)
  144. + name_count, printed_something, need_separator,
  145. + firstline, NULL, NULL)) != 0)
  146. break;
  147. - *printed_something |= xprinted_something;
  148. - *need_separator |= xneed_separator;
  149. }
  150. if ((ms->flags & MAGIC_DEBUG) != 0)
  151. @@ -1919,7 +1915,7 @@
  152. eoffset = ms->eoffset;
  153. rv = match(ms, ml.magic, ml.magic_rxcomp, ml.nmagic, b,
  154. offset + o, mode, text, flip, indir_count, name_count,
  155. - printed_something, need_separator, returnval,
  156. + printed_something, need_separator, firstline, returnval,
  157. &nfound_match);
  158. ms->ms_value.q = nfound_match;
  159. (*name_count)--;