cherry-pick.FILE5_30-01-g64e45647.more-cast-stuff.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. Subject: More cast stuff
  2. Origin: FILE5_30-1-g64e45647
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Fri Feb 10 18:14:01 2017 +0000
  5. --- a/src/apprentice.c
  6. +++ b/src/apprentice.c
  7. @@ -549,8 +549,10 @@
  8. break;
  9. case MAP_TYPE_MALLOC:
  10. for (i = 0; i < MAGIC_SETS; i++) {
  11. - if ((char *)map->magic[i] >= (char *)map->p &&
  12. - (char *)map->magic[i] <= (char *)map->p + map->len)
  13. + void *b = map->magic[i];
  14. + void *p = map->p;
  15. + if (CAST(char *, b) >= CAST(char *, p) &&
  16. + CAST(char *, b) <= CAST(char *, p) + map->len)
  17. continue;
  18. free(map->magic[i]);
  19. }
  20. --- a/src/cdf.c
  21. +++ b/src/cdf.c
  22. @@ -811,7 +811,7 @@
  23. == 0)
  24. break;
  25. if (i > 0)
  26. - return i;
  27. + return CAST(int, i);
  28. DPRINTF(("Cannot find type %d `%s'\n", type, name));
  29. errno = ESRCH;
  30. @@ -1068,7 +1068,7 @@
  31. {
  32. size_t ss = cdf_check_stream(sst, h);
  33. const char *b = CAST(const char *, sst->sst_tab);
  34. - const char *eb = b + ss * sst->sst_len;
  35. + const char *nb, *eb = b + ss * sst->sst_len;
  36. size_t nr, i, j, k;
  37. cdf_catalog_entry_t *ce;
  38. uint16_t reclen;
  39. @@ -1113,7 +1113,9 @@
  40. cep->ce_namlen = rlen;
  41. np = CAST(const uint16_t *, CAST(const void *, (b + 16)));
  42. - if (RCAST(const char *, np + cep->ce_namlen) > eb) {
  43. + nb = CAST(const char *, CAST(const void *,
  44. + (np + cep->ce_namlen)));
  45. + if (nb > eb) {
  46. cep->ce_namlen = 0;
  47. break;
  48. }
  49. --- a/src/compress.c
  50. +++ b/src/compress.c
  51. @@ -94,7 +94,7 @@
  52. zlibcmp(const unsigned char *buf)
  53. {
  54. unsigned short x = 1;
  55. - unsigned char *s = (unsigned char *)&x;
  56. + unsigned char *s = CCAST(unsigned char *, &x);
  57. if ((buf[0] & 0xf) != 8 || (buf[0] & 0x80) != 0)
  58. return 0;
  59. @@ -498,7 +498,7 @@
  60. z.next_in = CCAST(Bytef *, old);
  61. z.avail_in = CAST(uint32_t, *n);
  62. z.next_out = *newch;
  63. - z.avail_out = bytes_max;
  64. + z.avail_out = CAST(unsigned int, bytes_max);
  65. z.zalloc = Z_NULL;
  66. z.zfree = Z_NULL;
  67. z.opaque = Z_NULL;
  68. @@ -633,7 +633,7 @@
  69. while (isspace((unsigned char)*p))
  70. p++;
  71. n = strlen(p);
  72. - memmove(ubuf, p, n + 1);
  73. + memmove(ubuf, p, CAST(size_t, n + 1));
  74. }
  75. DPRINTF("Filter error after[[[%s]]]\n", (char *)ubuf);
  76. if (islower(*ubuf))
  77. @@ -689,7 +689,7 @@
  78. }
  79. for (i = 0; i < __arraycount(fdp); i++)
  80. - copydesc(i, fdp[i]);
  81. + copydesc(CAST(int, i), fdp[i]);
  82. (void)execvp(compr[method].argv[0],
  83. (char *const *)(intptr_t)compr[method].argv);
  84. --- a/src/der.c
  85. +++ b/src/der.c
  86. @@ -201,7 +201,7 @@
  87. if (*p + len >= l)
  88. return DER_BAD;
  89. - return len;
  90. + return CAST(uint32_t, len);
  91. }
  92. static const char *
  93. @@ -260,12 +260,12 @@
  94. #endif
  95. if (m->cont_level != 0) {
  96. if (offs + tlen > nbytes)
  97. - return DER_BAD;
  98. - ms->c.li[m->cont_level - 1].off = offs + tlen;
  99. + return -1;
  100. + ms->c.li[m->cont_level - 1].off = CAST(int, offs + tlen);
  101. DPRINTF(("cont_level[%u] = %u\n", m->cont_level - 1,
  102. ms->c.li[m->cont_level - 1].off));
  103. }
  104. - return offs;
  105. + return CAST(int32_t, offs);
  106. }
  107. int
  108. --- a/src/print.c
  109. +++ b/src/print.c
  110. @@ -238,7 +238,7 @@
  111. if (flags & FILE_T_WINDOWS) {
  112. struct timespec ts;
  113. - cdf_timestamp_to_timespec(&ts, v);
  114. + cdf_timestamp_to_timespec(&ts, CAST(cdf_timestamp_t, v));
  115. t = ts.tv_sec;
  116. } else {
  117. // XXX: perhaps detect and print something if overflow
  118. --- a/src/readelf.c
  119. +++ b/src/readelf.c
  120. @@ -890,7 +890,7 @@
  121. offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num,
  122. fsize, virtaddr);
  123. - if ((buflen = pread(fd, buf, buflen, offset)) <= 0) {
  124. + if ((buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) {
  125. file_badread(ms);
  126. return 0;
  127. }
  128. --- a/src/softmagic.c
  129. +++ b/src/softmagic.c
  130. @@ -1017,9 +1017,8 @@
  131. mconvert(struct magic_set *ms, struct magic *m, int flip)
  132. {
  133. union VALUETYPE *p = &ms->ms_value;
  134. - uint8_t type;
  135. - switch (type = cvt_flip(m->type, flip)) {
  136. + switch (cvt_flip(m->type, flip)) {
  137. case FILE_BYTE:
  138. if (cvt_8(p, m) == -1)
  139. goto out;
  140. @@ -1184,7 +1183,7 @@
  141. case FILE_DER:
  142. case FILE_SEARCH:
  143. if (offset > nbytes)
  144. - offset = nbytes;
  145. + offset = CAST(uint32_t, nbytes);
  146. ms->search.s = RCAST(const char *, s) + offset;
  147. ms->search.s_len = nbytes - offset;
  148. ms->search.offset = offset;