History

In avcodec_open(), set return code to an error value only when an error occurs instead of unconditionally at the start of the function.

This fixes a bug where a successful call to ff_thread_init() masks errors that occur after that point in the function. It also makes future bugs like this less likely since the error code is now set near to the point in the code where the error is found.

Justin Ruggles committed 15 years ago

Commit 31d76ec1 parent cda7aa91 file · +8 −3Browse files

Unified · Split

libavcodec/utils.c+8−3
@@ -456,7 +456,7 @@ AVFrame *avcodec_alloc_frame(void){ · 455 unmodified lines
456456
457457 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
458458 {
459− int ret= -1;
459+ int ret = 0;
460460
461461 /* If there is a user-supplied mutex locking routine, call it. */
462462 if (ff_lockmgr_cb) {
@@ -467,11 +467,14 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 4 unmodified lines
467467 entangled_thread_counter++;
468468 if(entangled_thread_counter != 1){
469469 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
470+ ret = -1;
470471 goto end;
471472 }
472473
473− if(avctx->codec || !codec)
474+ if(avctx->codec || !codec) {
475+ ret = AVERROR(EINVAL);
474476 goto end;
477+ }
475478
476479 if (codec->priv_data_size > 0) {
477480 if(!avctx->priv_data){
@@ -521,6 +524,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 43 unmodified lines
521524 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
522525 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
523526 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
527+ ret = AVERROR(EINVAL);
524528 goto free_and_end;
525529 }
526530 avctx->frame_number = 0;
@@ -535,6 +539,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 8 unmodified lines
535539 if (avctx->codec->max_lowres < avctx->lowres) {
536540 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
537541 avctx->codec->max_lowres);
542+ ret = AVERROR(EINVAL);
538543 goto free_and_end;
539544 }
540545 if (avctx->codec->sample_fmts && avctx->codec->encode) {
@@ -544,6 +549,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 3 unmodified lines
544549 break;
545550 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
546551 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
552+ ret = AVERROR(EINVAL);
547553 goto free_and_end;
548554 }
549555 }
@@ -554,7 +560,6 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 4 unmodified lines
554560 goto free_and_end;
555561 }
556562 }
557− ret=0;
558563 end:
559564 entangled_thread_counter--;
560565

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t