Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_vorbis: logically dead code in decode_residue #842

Closed
kcgen opened this issue Nov 25, 2019 · 1 comment · Fixed by #854 or dosbox-staging/dosbox-staging#71
Closed

stb_vorbis: logically dead code in decode_residue #842

kcgen opened this issue Nov 25, 2019 · 1 comment · Fixed by #854 or dosbox-staging/dosbox-staging#71

Comments

@kcgen
Copy link
Contributor

kcgen commented Nov 25, 2019

2126 static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int rn, uint8 *do_not_decode)
2127{
2128   int i,j,pass;
2129   Residue *r = f->residue_config + rn;
2130   int rtype = f->residue_types[rn];
2131   int c = r->classbook;
2132   int classwords = f->codebooks[c].dimensions;
2133   unsigned int actual_size = rtype == 2 ? n*2 : n;
2134   unsigned int limit_r_begin = (r->begin < actual_size ? r->begin : actual_size);
2135   unsigned int limit_r_end   = (r->end   < actual_size ? r->end   : actual_size);
2136   int n_read = limit_r_end - limit_r_begin;
2137   int part_read = n_read / r->part_size;
2138   int temp_alloc_point = temp_alloc_save(f);
2139   #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
    	CID 24071: Wrong sizeof argument (SIZEOF_MISMATCH) [select issue]
2140   uint8 ***part_classdata = (uint8 ***) temp_block_array(f,f->channels, part_read * sizeof(**part_classdata));
2141   #else
2142   int **classifications = (int **) temp_block_array(f,f->channels, part_read * sizeof(**classifications));
2143   #endif
2144
2145   CHECK(f);
2146
    	cond_at_most: Condition i < ch, taking false branch. Now the value of ch is at most 0.
    	cond_at_least: Condition i < ch, taking true branch. Now the value of ch is at least 1.
    	cond_at_least: Condition i < ch, taking true branch. Now the value of ch is at least 2.
    	assignment: Assigning: i = 0.
    	incr: Incrementing i. The value of i is now 1.
2147   for (i=0; i < ch; ++i)
2148      if (!do_not_decode[i])
2149         memset(residue_buffers[i], 0, sizeof(float) * n);
2150
    	cond_cannot_single: Condition ch != 1, taking true branch. Now the value of ch cannot be equal to 1.
2151   if (rtype == 2 && ch != 1) {
    	cond_at_most: Condition j < ch, taking false branch. Now the value of ch is at most 0.
    	cond_at_least: Condition j < ch, taking true branch. Now the value of ch is at least 2.
    	incr: Incrementing j. The value of j is now 1.
    	cond_at_least: Condition j < ch, taking true branch. Now the value of ch is at least 3.
    	assignment: Assigning: j = 0.
    	incr: Incrementing j. The value of j is now 2.
2152      for (j=0; j < ch; ++j)
2153         if (!do_not_decode[j])
2154            break;
    	cond_cannot_set: Condition j == ch, taking false branch. Now the value of ch cannot be equal to any of {0, 1}.
2155      if (j == ch)
2156         goto done;
2157
2158      for (pass=0; pass < 8; ++pass) {
2159         int pcount = 0, class_set = 0;
    	cond_cannot_set: Condition ch == 2, taking false branch. Now the value of ch cannot be equal to any of {0, 1, 2}.
    	cond_cannot_set: Condition ch == 2, taking false branch. Now the value of ch cannot be equal to any of {1, 2}.
2160         if (ch == 2) {
2161            while (pcount < part_read) {
2162               int z = r->begin + pcount*r->part_size;
2163               int c_inter = (z & 1), p_inter = z>>1;
2164               if (pass == 0) {
2165                  Codebook *c = f->codebooks+r->classbook;
2166                  int q;
2167                  DECODE(q,f,c);
2168                  if (q == EOP) goto done;
2169                  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2170                  part_classdata[0][class_set] = r->classdata[q];
2171                  #else
2172                  for (i=classwords-1; i >= 0; --i) {
2173                     classifications[0][i+pcount] = q % r->classifications;
2174                     q /= r->classifications;
2175                  }
2176                  #endif
2177               }
2178               for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2179                  int z = r->begin + pcount*r->part_size;
2180                  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2181                  int c = part_classdata[0][class_set][i];
2182                  #else
2183                  int c = classifications[0][pcount];
2184                  #endif
2185                  int b = r->residue_books[c][pass];
2186                  if (b >= 0) {
2187                     Codebook *book = f->codebooks + b;
2188                     #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
2189                     if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
2190                        goto done;
2191                     #else
2192                     // saves 1%
2193                     if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
2194                        goto done;
2195                     #endif
2196                  } else {
2197                     z += r->part_size;
2198                     c_inter = z & 1;
2199                     p_inter = z >> 1;
2200                  }
2201               }
2202               #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2203               ++class_set;
2204               #endif
2205            }
    	intervals: At condition ch == 1, the value of ch must be in one of the following intervals: {(-inf,-1], [3,+inf)}.
    	cannot_set: At condition ch == 1, the value of ch cannot be equal to any of {1, 2}.
    	dead_error_condition: The condition ch == 1 cannot be true.
2206         } else if (ch == 1) {
    	
CID 24053 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement: while (pcount < part_read) ....
2207            while (pcount < part_read) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants