diff --git a/cmdutils.c b/cmdutils.c index a8200012e5..8ef477fd01 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -1320,7 +1320,7 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) ret = AVERROR_EOF; } else { ret = 0; - (*bufptr)[*size++] = '\0'; + (*bufptr)[(*size)++] = '\0'; } fclose(f); diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 26dcdff856..4db881b721 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -1296,8 +1296,14 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata) { AVFormatContext *is = ifile->ctx; AVFormatContext *os = ofile->ctx; + AVChapter **tmp; int i; + tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters)); + if (!tmp) + return AVERROR(ENOMEM); + os->chapters = tmp; + for (i = 0; i < is->nb_chapters; i++) { AVChapter *in_ch = is->chapters[i], *out_ch; int64_t ts_off = av_rescale_q(ofile->start_time - ifile->ts_offset, @@ -1323,11 +1329,7 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata) if (copy_metadata) av_dict_copy(&out_ch->metadata, in_ch->metadata, 0); - os->nb_chapters++; - os->chapters = av_realloc_f(os->chapters, os->nb_chapters, sizeof(AVChapter)); - if (!os->chapters) - return AVERROR(ENOMEM); - os->chapters[os->nb_chapters - 1] = out_ch; + os->chapters[os->nb_chapters++] = out_ch; } return 0; } diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index e7085f6d73..639d3174fa 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -5369,9 +5369,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, break; case VC1_CODE_FIELD: { int buf_size3; - slices = av_realloc(slices, sizeof(*slices) * (n_slices+1)); - if (!slices) + tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1)); + if (!tmp) goto err; + slices = tmp; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; @@ -5393,9 +5394,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, break; case VC1_CODE_SLICE: { int buf_size3; - slices = av_realloc(slices, sizeof(*slices) * (n_slices+1)); - if (!slices) + tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1)); + if (!tmp) goto err; + slices = tmp; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; @@ -5466,7 +5468,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, if (!s->context_initialized) { if (ff_msmpeg4_decode_init(avctx) < 0 || ff_vc1_decode_init_alloc_tables(v) < 0) - return -1; + goto err; s->low_delay = !avctx->has_b_frames || v->res_sprite; diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 9d0f998f62..c804cece49 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -280,8 +280,10 @@ static int output_frame(AVFilterLink *outlink, int nb_samples) return AVERROR(ENOMEM); in_buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples); - if (!in_buf) + if (!in_buf) { + avfilter_unref_buffer(out_buf); return AVERROR(ENOMEM); + } for (i = 0; i < s->nb_inputs; i++) { if (s->input_state[i] == INPUT_ON) { diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index 50289c3038..211abd752d 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -337,8 +337,8 @@ static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *bu if (buf->extended_data == buf->data) { buf->extended_data = new_extended_data; } else { - buf->extended_data = new_extended_data; av_free(buf->extended_data); + buf->extended_data = new_extended_data; } } else if (buf->extended_data != buf->data) { av_free(buf->extended_data); diff --git a/libavfilter/af_resample.c b/libavfilter/af_resample.c index 58a9b2a99e..c43d260610 100644 --- a/libavfilter/af_resample.c +++ b/libavfilter/af_resample.c @@ -194,9 +194,10 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) buf_out->linesize[0], nb_samples, buf->extended_data, buf->linesize[0], buf->audio->nb_samples); - if (ret < 0) { + if (ret <= 0) { avfilter_unref_buffer(buf_out); - goto fail; + if (ret < 0) + goto fail; } av_assert0(!avresample_available(s->avr)); diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 38518e3443..375f728e61 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -368,13 +368,13 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int64_t ts, int64_t clus { mkv_cuepoint *entries = cues->entries; + if (ts < 0) + return 0; + entries = av_realloc(entries, (cues->num_entries + 1) * sizeof(mkv_cuepoint)); if (entries == NULL) return AVERROR(ENOMEM); - if (ts < 0) - return 0; - entries[cues->num_entries ].pts = ts; entries[cues->num_entries ].tracknum = stream + 1; entries[cues->num_entries++].cluster_pos = cluster_pos - cues->segment_offset; diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c index 4a5be12783..b55f1a9ce4 100644 --- a/libavformat/swfenc.c +++ b/libavformat/swfenc.c @@ -187,6 +187,10 @@ static int swf_write_header(AVFormatContext *s) for(i=0;inb_streams;i++) { AVCodecContext *enc = s->streams[i]->codec; if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (swf->audio_enc) { + av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 audio stream\n"); + return AVERROR_INVALIDDATA; + } if (enc->codec_id == AV_CODEC_ID_MP3) { swf->audio_enc = enc; swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE); @@ -197,6 +201,10 @@ static int swf_write_header(AVFormatContext *s) return -1; } } else { + if (swf->video_enc) { + av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 video stream\n"); + return AVERROR_INVALIDDATA; + } if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_FLV1 || enc->codec_id == AV_CODEC_ID_MJPEG) { diff --git a/library.mak b/library.mak index 821fe7e3dd..cc77729c41 100644 --- a/library.mak +++ b/library.mak @@ -35,7 +35,7 @@ install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared define RULES $(EXAMPLES) $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o - $$(LD) $(LDFLAGS) $$(LD_O) $$^ $(FULLNAME:%=$(LD_LIB)) $(FFEXTRALIBS) $$(ELIBS) + $$(LD) $(LDFLAGS) $$(LD_O) $$^ $(FFEXTRALIBS) $$(ELIBS) $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR) $(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME) @@ -94,8 +94,8 @@ endef $(eval $(RULES)) -$(EXAMPLES) $(TESTPROGS) $(TOOLS): $(THIS_LIB) $(DEP_LIBS) -$(TESTPROGS): $(SUBDIR)$(LIBNAME) +$(EXAMPLES) $(TOOLS): $(THIS_LIB) $(DEP_LIBS) +$(TESTPROGS): $(SUBDIR)$(LIBNAME) $(DEP_LIBS) examples: $(EXAMPLES) testprogs: $(TESTPROGS)