Merge "fix some warnings from static analysis"

This commit is contained in:
skal
2013-09-13 13:00:12 -07:00
committed by Gerrit Code Review
10 changed files with 51 additions and 25 deletions

View File

@ -425,6 +425,7 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) {
MemBuffer* const mem = &dmux->mem_;
Frame* frame;
ParseStatus status;
int image_added = 0;
if (dmux->frames_ != NULL) 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->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0;
}
AddFrame(dmux, frame);
dmux->num_frames_ = 1;
} else {
free(frame);
if (!AddFrame(dmux, frame)) {
status = PARSE_ERROR; // last frame was left incomplete
} else {
image_added = 1;
dmux->num_frames_ = 1;
}
}
if (!image_added) free(frame);
return status;
}

View File

@ -153,6 +153,8 @@ static void AssignSegments(VP8Encoder* const enc,
// 'int' type is ok for histo, and won't overflow
int accum[NUM_MB_SEGMENTS], dist_accum[NUM_MB_SEGMENTS];
assert(nb >= 1);
// bracket the input
for (n = 0; n <= MAX_ALPHA && alphas[n] == 0; ++n) {}
min_a = n;
@ -161,8 +163,9 @@ static void AssignSegments(VP8Encoder* const enc,
range_a = max_a - min_a;
// Spread initial centers evenly
for (n = 1, k = 0; n < 2 * nb; n += 2) {
centers[k++] = min_a + (n * range_a) / (2 * nb);
for (k = 0, n = 1; k < nb; ++k, n += 2) {
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
@ -177,7 +180,7 @@ static void AssignSegments(VP8Encoder* const enc,
n = 0; // track the nearest center for current 'a'
for (a = min_a; a <= max_a; ++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++;
}
map[a] = n;

View File

@ -976,6 +976,7 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
assert(enc->use_tokens_);
assert(proba->use_skip_proba_ == 0);
assert(rd_opt >= RD_OPT_BASIC); // otherwise, token-buffer won't be useful
assert(num_pass_left > 0);
while (ok && num_pass_left-- > 0) {
const int is_last_pass = (fabs(stats.dq) <= DQ_LIMIT) ||

View File

@ -123,6 +123,7 @@ int WebPPictureAlloc(WebPPicture* picture) {
picture->v0 = mem;
mem += uv0_size;
}
(void)mem; // makes the static analyzer happy
} else {
void* memory;
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) {
assert(step >= 4);
assert(picture->a != NULL);
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
picture->a[x + y * picture->a_stride] =

View File

@ -403,10 +403,12 @@ static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi,
int* const duration,
int* const width, int* const height) {
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.
const WebPMuxError err =
GetFrameFragmentInfo(frame_frgm_chunk, x_offset, y_offset, duration);
err = GetFrameFragmentInfo(frame_frgm_chunk, x_offset, y_offset, duration);
if (err != WEBP_MUX_OK) return err;
// Get width and height from VP8/VP8L chunk.
@ -426,10 +428,12 @@ static WebPMuxError GetImageCanvasWidthHeight(
assert(wpi != NULL);
assert(wpi->img_ != NULL);
if (wpi->next_) {
if (wpi->next_ != NULL) {
int max_x = 0;
int max_y = 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.
for (; wpi != NULL; wpi = wpi->next_) {
int x_offset = 0, y_offset = 0, duration = 0, w = 0, h = 0;

View File

@ -43,7 +43,10 @@ static int BitWriterResize(VP8BitWriter* const bw, size_t extra_size) {
bw->error_ = 1;
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_);
bw->buf_ = new_buf;
bw->max_pos_ = new_size;