mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-30 18:05:36 +01:00 
			
		
		
		
	fix some warnings from static analysis
http://code.google.com/p/webp/issues/detail?id=138 Change-Id: I21470e965357cc14eab356e2c477c7846ff76ef2
This commit is contained in:
		| @@ -929,7 +929,7 @@ int main(int argc, const char *argv[]) { | |||||||
|  |  | ||||||
|   // Read the input |   // Read the input | ||||||
|   if (verbose) { |   if (verbose) { | ||||||
|     StopwatchReadAndReset(&stop_watch); |     StopwatchReset(&stop_watch); | ||||||
|   } |   } | ||||||
|   if (!ReadPicture(in_file, &picture, keep_alpha, |   if (!ReadPicture(in_file, &picture, keep_alpha, | ||||||
|                    (keep_metadata == 0) ? NULL : &metadata)) { |                    (keep_metadata == 0) ? NULL : &metadata)) { | ||||||
| @@ -983,7 +983,7 @@ int main(int argc, const char *argv[]) { | |||||||
|  |  | ||||||
|   // Compress |   // Compress | ||||||
|   if (verbose) { |   if (verbose) { | ||||||
|     StopwatchReadAndReset(&stop_watch); |     StopwatchReset(&stop_watch); | ||||||
|   } |   } | ||||||
|   if (crop != 0) { |   if (crop != 0) { | ||||||
|     // We use self-cropping using a view. |     // We use self-cropping using a view. | ||||||
|   | |||||||
| @@ -474,8 +474,9 @@ static int SaveOutput(const WebPDecBuffer* const buffer, | |||||||
|   int ok = 1; |   int ok = 1; | ||||||
|   Stopwatch stop_watch; |   Stopwatch stop_watch; | ||||||
|  |  | ||||||
|   if (verbose) |   if (verbose) { | ||||||
|     StopwatchReadAndReset(&stop_watch); |     StopwatchReset(&stop_watch); | ||||||
|  |   } | ||||||
|  |  | ||||||
| #ifdef HAVE_WINCODEC_H | #ifdef HAVE_WINCODEC_H | ||||||
|   needs_open_file = (format != PNG); |   needs_open_file = (format != PNG); | ||||||
| @@ -657,8 +658,9 @@ int main(int argc, const char *argv[]) { | |||||||
|  |  | ||||||
|     if (!ExUtilReadFile(in_file, &data, &data_size)) return -1; |     if (!ExUtilReadFile(in_file, &data, &data_size)) return -1; | ||||||
|  |  | ||||||
|     if (verbose) |     if (verbose) { | ||||||
|       StopwatchReadAndReset(&stop_watch); |       StopwatchReset(&stop_watch); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     status = WebPGetFeatures(data, data_size, bitstream); |     status = WebPGetFeatures(data, data_size, bitstream); | ||||||
|     if (status != VP8_STATUS_OK) { |     if (status != VP8_STATUS_OK) { | ||||||
|   | |||||||
| @@ -19,6 +19,10 @@ | |||||||
|  |  | ||||||
| typedef LARGE_INTEGER Stopwatch; | typedef LARGE_INTEGER Stopwatch; | ||||||
|  |  | ||||||
|  | static WEBP_INLINE void StopwatchReset(Stopwatch* watch) { | ||||||
|  |   QueryPerformanceCounter(watch); | ||||||
|  | } | ||||||
|  |  | ||||||
| static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) { | static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) { | ||||||
|   const LARGE_INTEGER old_value = *watch; |   const LARGE_INTEGER old_value = *watch; | ||||||
|   LARGE_INTEGER freq; |   LARGE_INTEGER freq; | ||||||
| @@ -37,6 +41,10 @@ static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) { | |||||||
|  |  | ||||||
| typedef struct timeval Stopwatch; | typedef struct timeval Stopwatch; | ||||||
|  |  | ||||||
|  | static WEBP_INLINE void StopwatchReset(Stopwatch* watch) { | ||||||
|  |   gettimeofday(watch, NULL); | ||||||
|  | } | ||||||
|  |  | ||||||
| static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) { | static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) { | ||||||
|   const struct timeval old_value = *watch; |   const struct timeval old_value = *watch; | ||||||
|   gettimeofday(watch, NULL); |   gettimeofday(watch, NULL); | ||||||
|   | |||||||
| @@ -57,7 +57,7 @@ static struct { | |||||||
|  |  | ||||||
|   const char* file_name; |   const char* file_name; | ||||||
|   WebPData data; |   WebPData data; | ||||||
|   WebPDecoderConfig* config; |   WebPDecoderConfig config; | ||||||
|   const WebPDecBuffer* pic; |   const WebPDecBuffer* pic; | ||||||
|   WebPDemuxer* dmux; |   WebPDemuxer* dmux; | ||||||
|   WebPIterator curr_frame; |   WebPIterator curr_frame; | ||||||
| @@ -146,7 +146,7 @@ static int ApplyColorProfile(const WebPData* const profile, | |||||||
|  |  | ||||||
| static int Decode(void) {   // Fills kParams.curr_frame | static int Decode(void) {   // Fills kParams.curr_frame | ||||||
|   const WebPIterator* const curr = &kParams.curr_frame; |   const WebPIterator* const curr = &kParams.curr_frame; | ||||||
|   WebPDecoderConfig* const config = kParams.config; |   WebPDecoderConfig* const config = &kParams.config; | ||||||
|   WebPDecBuffer* const output_buffer = &config->output; |   WebPDecBuffer* const output_buffer = &config->output; | ||||||
|   int ok = 0; |   int ok = 0; | ||||||
|  |  | ||||||
| @@ -386,16 +386,15 @@ static void Help(void) { | |||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||||
|   WebPDecoderConfig config; |  | ||||||
|   int c; |   int c; | ||||||
|  |   WebPDecoderConfig* const config = &kParams.config; | ||||||
|   WebPIterator* const curr = &kParams.curr_frame; |   WebPIterator* const curr = &kParams.curr_frame; | ||||||
|   WebPIterator* const prev = &kParams.prev_frame; |   WebPIterator* const prev = &kParams.prev_frame; | ||||||
|  |  | ||||||
|   if (!WebPInitDecoderConfig(&config)) { |   if (!WebPInitDecoderConfig(config)) { | ||||||
|     fprintf(stderr, "Library version mismatch!\n"); |     fprintf(stderr, "Library version mismatch!\n"); | ||||||
|     return -1; |     return -1; | ||||||
|   } |   } | ||||||
|   kParams.config = &config; |  | ||||||
|   kParams.use_color_profile = 1; |   kParams.use_color_profile = 1; | ||||||
|  |  | ||||||
|   for (c = 1; c < argc; ++c) { |   for (c = 1; c < argc; ++c) { | ||||||
| @@ -405,9 +404,9 @@ int main(int argc, char *argv[]) { | |||||||
|     } else if (!strcmp(argv[c], "-noicc")) { |     } else if (!strcmp(argv[c], "-noicc")) { | ||||||
|       kParams.use_color_profile = 0; |       kParams.use_color_profile = 0; | ||||||
|     } else if (!strcmp(argv[c], "-nofancy")) { |     } else if (!strcmp(argv[c], "-nofancy")) { | ||||||
|       config.options.no_fancy_upsampling = 1; |       config->options.no_fancy_upsampling = 1; | ||||||
|     } else if (!strcmp(argv[c], "-nofilter")) { |     } else if (!strcmp(argv[c], "-nofilter")) { | ||||||
|       config.options.bypass_filtering = 1; |       config->options.bypass_filtering = 1; | ||||||
|     } else if (!strcmp(argv[c], "-info")) { |     } else if (!strcmp(argv[c], "-info")) { | ||||||
|       kParams.print_info = 1; |       kParams.print_info = 1; | ||||||
|     } else if (!strcmp(argv[c], "-version")) { |     } else if (!strcmp(argv[c], "-version")) { | ||||||
| @@ -419,7 +418,7 @@ int main(int argc, char *argv[]) { | |||||||
|              (dmux_version >> 8) & 0xff, dmux_version & 0xff); |              (dmux_version >> 8) & 0xff, dmux_version & 0xff); | ||||||
|       return 0; |       return 0; | ||||||
|     } else if (!strcmp(argv[c], "-mt")) { |     } else if (!strcmp(argv[c], "-mt")) { | ||||||
|       config.options.use_threads = 1; |       config->options.use_threads = 1; | ||||||
|     } else if (argv[c][0] == '-') { |     } else if (argv[c][0] == '-') { | ||||||
|       printf("Unknown option '%s'\n", argv[c]); |       printf("Unknown option '%s'\n", argv[c]); | ||||||
|       Help(); |       Help(); | ||||||
|   | |||||||
| @@ -425,6 +425,7 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) { | |||||||
|   MemBuffer* const mem = &dmux->mem_; |   MemBuffer* const mem = &dmux->mem_; | ||||||
|   Frame* frame; |   Frame* frame; | ||||||
|   ParseStatus status; |   ParseStatus status; | ||||||
|  |   int image_added = 0; | ||||||
|  |  | ||||||
|   if (dmux->frames_ != NULL) return PARSE_ERROR; |   if (dmux->frames_ != NULL) return PARSE_ERROR; | ||||||
|   if (SizeIsInvalid(mem, min_size)) return PARSE_ERROR; |   if (SizeIsInvalid(mem, min_size)) return PARSE_ERROR; | ||||||
| @@ -453,12 +454,15 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) { | |||||||
|       dmux->canvas_height_ = frame->height_; |       dmux->canvas_height_ = frame->height_; | ||||||
|       dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0; |       dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0; | ||||||
|     } |     } | ||||||
|     AddFrame(dmux, frame); |     if (!AddFrame(dmux, frame)) { | ||||||
|     dmux->num_frames_ = 1; |       status = PARSE_ERROR;  // last frame was left incomplete | ||||||
|   } else { |     } else { | ||||||
|     free(frame); |       image_added = 1; | ||||||
|  |       dmux->num_frames_ = 1; | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   if (!image_added) free(frame); | ||||||
|   return status; |   return status; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -153,6 +153,8 @@ static void AssignSegments(VP8Encoder* const enc, | |||||||
|   // 'int' type is ok for histo, and won't overflow |   // 'int' type is ok for histo, and won't overflow | ||||||
|   int accum[NUM_MB_SEGMENTS], dist_accum[NUM_MB_SEGMENTS]; |   int accum[NUM_MB_SEGMENTS], dist_accum[NUM_MB_SEGMENTS]; | ||||||
|  |  | ||||||
|  |   assert(nb >= 1); | ||||||
|  |  | ||||||
|   // bracket the input |   // bracket the input | ||||||
|   for (n = 0; n <= MAX_ALPHA && alphas[n] == 0; ++n) {} |   for (n = 0; n <= MAX_ALPHA && alphas[n] == 0; ++n) {} | ||||||
|   min_a = n; |   min_a = n; | ||||||
| @@ -161,8 +163,9 @@ static void AssignSegments(VP8Encoder* const enc, | |||||||
|   range_a = max_a - min_a; |   range_a = max_a - min_a; | ||||||
|  |  | ||||||
|   // Spread initial centers evenly |   // Spread initial centers evenly | ||||||
|   for (n = 1, k = 0; n < 2 * nb; n += 2) { |   for (k = 0, n = 1; k < nb; ++k, n += 2) { | ||||||
|     centers[k++] = min_a + (n * range_a) / (2 * nb); |     assert(n < 2 * nb); | ||||||
|  |     centers[k] = min_a + (n * range_a) / (2 * nb); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   for (k = 0; k < MAX_ITERS_K_MEANS; ++k) {     // few iters are enough |   for (k = 0; k < MAX_ITERS_K_MEANS; ++k) {     // few iters are enough | ||||||
| @@ -177,7 +180,7 @@ static void AssignSegments(VP8Encoder* const enc, | |||||||
|     n = 0;    // track the nearest center for current 'a' |     n = 0;    // track the nearest center for current 'a' | ||||||
|     for (a = min_a; a <= max_a; ++a) { |     for (a = min_a; a <= max_a; ++a) { | ||||||
|       if (alphas[a]) { |       if (alphas[a]) { | ||||||
|         while (n < nb - 1 && abs(a - centers[n + 1]) < abs(a - centers[n])) { |         while (n + 1 < nb && abs(a - centers[n + 1]) < abs(a - centers[n])) { | ||||||
|           n++; |           n++; | ||||||
|         } |         } | ||||||
|         map[a] = n; |         map[a] = n; | ||||||
|   | |||||||
| @@ -976,6 +976,7 @@ int VP8EncTokenLoop(VP8Encoder* const enc) { | |||||||
|   assert(enc->use_tokens_); |   assert(enc->use_tokens_); | ||||||
|   assert(proba->use_skip_proba_ == 0); |   assert(proba->use_skip_proba_ == 0); | ||||||
|   assert(rd_opt >= RD_OPT_BASIC);   // otherwise, token-buffer won't be useful |   assert(rd_opt >= RD_OPT_BASIC);   // otherwise, token-buffer won't be useful | ||||||
|  |   assert(num_pass_left > 0); | ||||||
|  |  | ||||||
|   while (ok && num_pass_left-- > 0) { |   while (ok && num_pass_left-- > 0) { | ||||||
|     const int is_last_pass = (fabs(stats.dq) <= DQ_LIMIT) || |     const int is_last_pass = (fabs(stats.dq) <= DQ_LIMIT) || | ||||||
|   | |||||||
| @@ -123,6 +123,7 @@ int WebPPictureAlloc(WebPPicture* picture) { | |||||||
|         picture->v0 = mem; |         picture->v0 = mem; | ||||||
|         mem += uv0_size; |         mem += uv0_size; | ||||||
|       } |       } | ||||||
|  |       (void)mem;  // makes the static analyzer happy | ||||||
|     } else { |     } else { | ||||||
|       void* memory; |       void* memory; | ||||||
|       const uint64_t argb_size = (uint64_t)width * height; |       const uint64_t argb_size = (uint64_t)width * height; | ||||||
| @@ -698,6 +699,7 @@ static int ImportYUVAFromRGBA(const uint8_t* const r_ptr, | |||||||
|  |  | ||||||
|   if (has_alpha) { |   if (has_alpha) { | ||||||
|     assert(step >= 4); |     assert(step >= 4); | ||||||
|  |     assert(picture->a != NULL); | ||||||
|     for (y = 0; y < height; ++y) { |     for (y = 0; y < height; ++y) { | ||||||
|       for (x = 0; x < width; ++x) { |       for (x = 0; x < width; ++x) { | ||||||
|         picture->a[x + y * picture->a_stride] = |         picture->a[x + y * picture->a_stride] = | ||||||
|   | |||||||
| @@ -403,10 +403,12 @@ static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi, | |||||||
|                                  int* const duration, |                                  int* const duration, | ||||||
|                                  int* const width, int* const height) { |                                  int* const width, int* const height) { | ||||||
|   const WebPChunk* const frame_frgm_chunk = wpi->header_; |   const WebPChunk* const frame_frgm_chunk = wpi->header_; | ||||||
|  |   WebPMuxError err; | ||||||
|  |   assert(wpi != NULL); | ||||||
|  |   assert(frame_frgm_chunk != NULL); | ||||||
|  |  | ||||||
|   // Get offsets and duration from ANMF/FRGM chunk. |   // Get offsets and duration from ANMF/FRGM chunk. | ||||||
|   const WebPMuxError err = |   err = GetFrameFragmentInfo(frame_frgm_chunk, x_offset, y_offset, duration); | ||||||
|       GetFrameFragmentInfo(frame_frgm_chunk, x_offset, y_offset, duration); |  | ||||||
|   if (err != WEBP_MUX_OK) return err; |   if (err != WEBP_MUX_OK) return err; | ||||||
|  |  | ||||||
|   // Get width and height from VP8/VP8L chunk. |   // Get width and height from VP8/VP8L chunk. | ||||||
| @@ -426,10 +428,12 @@ static WebPMuxError GetImageCanvasWidthHeight( | |||||||
|   assert(wpi != NULL); |   assert(wpi != NULL); | ||||||
|   assert(wpi->img_ != NULL); |   assert(wpi->img_ != NULL); | ||||||
|  |  | ||||||
|   if (wpi->next_) { |   if (wpi->next_ != NULL) { | ||||||
|     int max_x = 0; |     int max_x = 0; | ||||||
|     int max_y = 0; |     int max_y = 0; | ||||||
|     int64_t image_area = 0; |     int64_t image_area = 0; | ||||||
|  |     // if we have a chain of wpi's, header_ is necessarily set | ||||||
|  |     assert(wpi->header_ != NULL); | ||||||
|     // Aggregate the bounding box for animation frames & fragmented images. |     // Aggregate the bounding box for animation frames & fragmented images. | ||||||
|     for (; wpi != NULL; wpi = wpi->next_) { |     for (; wpi != NULL; wpi = wpi->next_) { | ||||||
|       int x_offset = 0, y_offset = 0, duration = 0, w = 0, h = 0; |       int x_offset = 0, y_offset = 0, duration = 0, w = 0, h = 0; | ||||||
|   | |||||||
| @@ -43,7 +43,10 @@ static int BitWriterResize(VP8BitWriter* const bw, size_t extra_size) { | |||||||
|     bw->error_ = 1; |     bw->error_ = 1; | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
|   memcpy(new_buf, bw->buf_, bw->pos_); |   if (bw->pos_ > 0) { | ||||||
|  |     assert(bw->buf_ != NULL); | ||||||
|  |     memcpy(new_buf, bw->buf_, bw->pos_); | ||||||
|  |   } | ||||||
|   free(bw->buf_); |   free(bw->buf_); | ||||||
|   bw->buf_ = new_buf; |   bw->buf_ = new_buf; | ||||||
|   bw->max_pos_ = new_size; |   bw->max_pos_ = new_size; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user