ffmpeg.c:3739: error: Null Dereference
  pointer `oc` last assigned on line 3717 could be null and is dereferenced at line 3739, column 5.

ffmpeg.c:3706:1: start of procedure opt_output_file()
3704. }
3705. 
3706. static void opt_output_file(const char *filename)
      ^
3707. {
3708.     AVFormatContext *oc;

ffmpeg.c:3711:5: 
3709.     int err, use_video, use_audio, use_subtitle;
3710.     int input_has_video, input_has_audio, input_has_subtitle;
3711.     AVFormatParameters params, *ap = &params;
          ^
3712.     AVOutputFormat *file_oformat;
3713. 

ffmpeg.c:3714:10: Taking false branch
3712.     AVOutputFormat *file_oformat;
3713. 
3714.     if (!strcmp(filename, "-"))
               ^
3715.         filename = "pipe:";
3716. 

ffmpeg.c:3717:5: 
3715.         filename = "pipe:";
3716. 
3717.     oc = avformat_alloc_context();
          ^
3718.     if (!oc) {
3719.         print_error(filename, AVERROR(ENOMEM));

libavformat/options.c:82:1: start of procedure avformat_alloc_context()
  80. }
  81. 
  82. AVFormatContext *avformat_alloc_context(void)
      ^
  83. {
  84.     AVFormatContext *ic;

libavformat/options.c:85:5: 
  83. {
  84.     AVFormatContext *ic;
  85.     ic = av_malloc(sizeof(AVFormatContext));
          ^
  86.     if (!ic) return ic;
  87.     avformat_get_context_defaults(ic);

libavutil/mem.c:64:1: start of procedure av_malloc()
    62.    linker will do it automatically. */
    63. 
    64. void *av_malloc(unsigned int size)
        ^
    65. {
    66.     void *ptr = NULL;

libavutil/mem.c:66:5: 
    64. void *av_malloc(unsigned int size)
    65. {
    66.     void *ptr = NULL;
            ^
    67. #if CONFIG_MEMALIGN_HACK
    68.     long diff;

libavutil/mem.c:72:8: Taking false branch
    70. 
    71.     /* let's disallow possible ambiguous cases */
    72.     if(size > (INT_MAX-16) )
               ^
    73.         return NULL;
    74. 

libavutil/mem.c:83:9: Taking false branch
    81.     ((char*)ptr)[-1]= diff;
    82. #elif HAVE_POSIX_MEMALIGN
    83.     if (posix_memalign(&ptr,16,size))
                ^
    84.         ptr = NULL;
    85. #elif HAVE_MEMALIGN

libavutil/mem.c:116:5: 
    114.     ptr = malloc(size);
    115. #endif
    116.     return ptr;
             ^
    117. }
    118. 

libavutil/mem.c:117:1: return from a call to av_malloc
    115. #endif
    116.     return ptr;
    117. }
         ^
    118. 
    119. void *av_realloc(void *ptr, unsigned int size)

libavformat/options.c:86:10: Taking true branch
  84.     AVFormatContext *ic;
  85.     ic = av_malloc(sizeof(AVFormatContext));
  86.     if (!ic) return ic;
               ^
  87.     avformat_get_context_defaults(ic);
  88.     ic->av_class = &av_format_context_class;

libavformat/options.c:86:14: 
  84.     AVFormatContext *ic;
  85.     ic = av_malloc(sizeof(AVFormatContext));
  86.     if (!ic) return ic;
                   ^
  87.     avformat_get_context_defaults(ic);
  88.     ic->av_class = &av_format_context_class;

libavformat/options.c:90:1: return from a call to avformat_alloc_context
  88.     ic->av_class = &av_format_context_class;
  89.     return ic;
  90. }
      ^
  91. 
  92. #if LIBAVFORMAT_VERSION_MAJOR < 53

ffmpeg.c:3718:10: Taking true branch
3716. 
3717.     oc = avformat_alloc_context();
3718.     if (!oc) {
               ^
3719.         print_error(filename, AVERROR(ENOMEM));
3720.         ffmpeg_exit(1);

ffmpeg.c:3719:9: 
3717.     oc = avformat_alloc_context();
3718.     if (!oc) {
3719.         print_error(filename, AVERROR(ENOMEM));
              ^
3720.         ffmpeg_exit(1);
3721.     }

cmdutils.c:342:1: start of procedure print_error()
  340. }
  341. 
  342. void print_error(const char *filename, int err)
       ^
  343. {
  344.     char errbuf[128];

cmdutils.c:345:5: 
  343. {
  344.     char errbuf[128];
  345.     const char *errbuf_ptr = errbuf;
           ^
  346. 
  347.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)

cmdutils.c:347:9: 
  345.     const char *errbuf_ptr = errbuf;
  346. 
  347.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
               ^
  348.         errbuf_ptr = strerror(AVUNERROR(err));
  349.     fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);

libavutil/error.c:22:1: start of procedure av_strerror()
    20. #include "avstring.h"
    21. 
    22. int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
        ^
    23. {
    24.     int ret = 0;

libavutil/error.c:24:5: 
    22. int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
    23. {
    24.     int ret = 0;
            ^
    25.     const char *errstr = NULL;
    26. 

libavutil/error.c:25:5: 
    23. {
    24.     int ret = 0;
    25.     const char *errstr = NULL;
            ^
    26. 
    27.     switch (errnum) {

libavutil/error.c:27:5: 
    25.     const char *errstr = NULL;
    26. 
    27.     switch (errnum) {
            ^
    28.     case AVERROR_EOF:               errstr = "End of file"; break;
    29.     case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;

libavutil/error.c:28:5: Switch condition is false. Skipping switch case
    26. 
    27.     switch (errnum) {
    28.     case AVERROR_EOF:               errstr = "End of file"; break;
            ^
    29.     case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;
    30.     case AVERROR_NUMEXPECTED:       errstr = "Number syntax expected in filename"; break;

libavutil/error.c:29:5: Switch condition is false. Skipping switch case
    27.     switch (errnum) {
    28.     case AVERROR_EOF:               errstr = "End of file"; break;
    29.     case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;
            ^
    30.     case AVERROR_NUMEXPECTED:       errstr = "Number syntax expected in filename"; break;
    31.     case AVERROR_PATCHWELCOME:      errstr = "Not yet implemented in FFmpeg, patches welcome"; break;

libavutil/error.c:30:5: Switch condition is false. Skipping switch case
    28.     case AVERROR_EOF:               errstr = "End of file"; break;
    29.     case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;
    30.     case AVERROR_NUMEXPECTED:       errstr = "Number syntax expected in filename"; break;
            ^
    31.     case AVERROR_PATCHWELCOME:      errstr = "Not yet implemented in FFmpeg, patches welcome"; break;
    32.     }

libavutil/error.c:31:5: Switch condition is false. Skipping switch case
    29.     case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;
    30.     case AVERROR_NUMEXPECTED:       errstr = "Number syntax expected in filename"; break;
    31.     case AVERROR_PATCHWELCOME:      errstr = "Not yet implemented in FFmpeg, patches welcome"; break;
            ^
    32.     }
    33. 

libavutil/error.c:34:9: Taking false branch
    32.     }
    33. 
    34.     if (errstr) {
                ^
    35.         av_strlcpy(errbuf, errstr, errbuf_size);
    36.     } else {

libavutil/error.c:38:9: 
    36.     } else {
    37. #if HAVE_STRERROR_R
    38.         ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
                ^
    39. #else
    40.         ret = -1;

libavutil/error.c:42:13: Taking false branch
    40.         ret = -1;
    41. #endif
    42.         if (ret < 0)
                    ^
    43.             snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
    44.     }

libavutil/error.c:46:5: 
    44.     }
    45. 
    46.     return ret;
            ^
    47. }

libavutil/error.c:47:1: return from a call to av_strerror
    45. 
    46.     return ret;
    47. }
        ^

cmdutils.c:347:9: Taking false branch
  345.     const char *errbuf_ptr = errbuf;
  346. 
  347.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
               ^
  348.         errbuf_ptr = strerror(AVUNERROR(err));
  349.     fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);

cmdutils.c:349:5: 
  347.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
  348.         errbuf_ptr = strerror(AVUNERROR(err));
  349.     fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);
           ^
  350. }
  351. 

cmdutils.c:350:1: return from a call to print_error
  348.         errbuf_ptr = strerror(AVUNERROR(err));
  349.     fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);
  350. }
       ^
  351. 
  352. static int warned_cfg = 0;

ffmpeg.c:3720:9: Skipping ffmpeg_exit(): empty list of specs
3718.     if (!oc) {
3719.         print_error(filename, AVERROR(ENOMEM));
3720.         ffmpeg_exit(1);
              ^
3721.     }
3722. 

ffmpeg.c:3723:9: Taking true branch
3721.     }
3722. 
3723.     if (last_asked_format) {
              ^
3724.         file_oformat = av_guess_format(last_asked_format, NULL, NULL);
3725.         if (!file_oformat) {

ffmpeg.c:3724:9: Skipping av_guess_format(): empty list of specs
3722. 
3723.     if (last_asked_format) {
3724.         file_oformat = av_guess_format(last_asked_format, NULL, NULL);
              ^
3725.         if (!file_oformat) {
3726.             fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);

ffmpeg.c:3725:14: Taking false branch
3723.     if (last_asked_format) {
3724.         file_oformat = av_guess_format(last_asked_format, NULL, NULL);
3725.         if (!file_oformat) {
                   ^
3726.             fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
3727.             ffmpeg_exit(1);

ffmpeg.c:3729:9: 
3727.             ffmpeg_exit(1);
3728.         }
3729.         last_asked_format = NULL;
              ^
3730.     } else {
3731.         file_oformat = av_guess_format(NULL, filename, NULL);

ffmpeg.c:3739:5: 
3737.     }
3738. 
3739.     oc->oformat = file_oformat;
          ^
3740.     av_strlcpy(oc->filename, filename, sizeof(oc->filename));
3741. 

static void opt_output_file(const char *filename)
{
    AVFormatContext *oc;
    int err, use_video, use_audio, use_subtitle;
    int input_has_video, input_has_audio, input_has_subtitle;
    AVFormatParameters params, *ap = &params;
    AVOutputFormat *file_oformat;
    if (!strcmp(filename, "-"))
        filename = "pipe:";
    oc = avformat_alloc_context();
    if (!oc) {
        print_error(filename, AVERROR(ENOMEM));
        ffmpeg_exit(1);
    }
    if (last_asked_format) {
        file_oformat = av_guess_format(last_asked_format, NULL, NULL);
        if (!file_oformat) {
            fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
            ffmpeg_exit(1);
        }
        last_asked_format = NULL;
    } else {
        file_oformat = av_guess_format(NULL, filename, NULL);
        if (!file_oformat) {
            fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
                    filename);
            ffmpeg_exit(1);
        }
    }
    oc->oformat = file_oformat;
    av_strlcpy(oc->filename, filename, sizeof(oc->filename));
    if (!strcmp(file_oformat->name, "ffm") &&
        av_strstart(filename, "http:", NULL)) {
        int err = read_ffserver_streams(oc, filename);
        if (err < 0) {
            print_error(filename, err);
            ffmpeg_exit(1);
        }
    } else {
        use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
        use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
        use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
        if (nb_input_files > 0) {
            check_audio_video_sub_inputs(&input_has_video, &input_has_audio,
                                         &input_has_subtitle);
            if (!input_has_video)
                use_video = 0;
            if (!input_has_audio)
                use_audio = 0;
            if (!input_has_subtitle)
                use_subtitle = 0;
        }
        if (audio_disable) {
            use_audio = 0;
        }
        if (video_disable) {
            use_video = 0;
        }
        if (subtitle_disable) {
            use_subtitle = 0;
        }
        if (use_video) {
            new_video_stream(oc, nb_output_files);
        }
        if (use_audio) {
            new_audio_stream(oc, nb_output_files);
        }
        if (use_subtitle) {
            new_subtitle_stream(oc, nb_output_files);
        }
        oc->timestamp = recording_timestamp;
        for(; metadata_count>0; metadata_count--){
            av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key,
                                            metadata[metadata_count-1].value, 0);
        }
        av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);
    }
    output_files[nb_output_files++] = oc;
    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
        if (!av_filename_number_test(oc->filename)) {
            print_error(oc->filename, AVERROR_NUMEXPECTED);
            ffmpeg_exit(1);
        }
    }
    if (!(oc->oformat->flags & AVFMT_NOFILE)) {
        if (!file_overwrite &&
            (strchr(filename, ':') == NULL ||
             filename[1] == ':' ||
             av_strstart(filename, "file:", NULL))) {
            if (url_exist(filename)) {
                if (!using_stdin) {
                    fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
                    fflush(stderr);
                    if (!read_yesno()) {
                        fprintf(stderr, "Not overwriting - exiting\n");
                        ffmpeg_exit(1);
                    }
                }
                else {
                    fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
                    ffmpeg_exit(1);
                }
            }
        }
        if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {
            print_error(filename, err);
            ffmpeg_exit(1);
        }
    }
    memset(ap, 0, sizeof(*ap));
    if (av_set_parameters(oc, ap) < 0) {
        fprintf(stderr, "%s: Invalid encoding parameters\n",
                oc->filename);
        ffmpeg_exit(1);
    }
    oc->preload= (int)(mux_preload*AV_TIME_BASE);
    oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
    oc->loop_output = loop_output;
    oc->flags |= AVFMT_FLAG_NONBLOCK;
    set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
    nb_streamid_map = 0;
}
['static void opt_output_file(const char *filename)\n{\n    AVFormatContext *oc;\n    int err, use_video, use_audio, use_subtitle;\n    int input_has_video, input_has_audio, input_has_subtitle;\n    AVFormatParameters params, *ap = &params;\n    AVOutputFormat *file_oformat;\n    if (!strcmp(filename, "-"))\n        filename = "pipe:";\n    oc = avformat_alloc_context();\n    if (!oc) {\n        print_error(filename, AVERROR(ENOMEM));\n        ffmpeg_exit(1);\n    }\n    if (last_asked_format) {\n        file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n        if (!file_oformat) {\n            fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n            ffmpeg_exit(1);\n        }\n        last_asked_format = NULL;\n    } else {\n        file_oformat = av_guess_format(NULL, filename, NULL);\n        if (!file_oformat) {\n            fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n                    filename);\n            ffmpeg_exit(1);\n        }\n    }\n    oc->oformat = file_oformat;\n    av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n    if (!strcmp(file_oformat->name, "ffm") &&\n        av_strstart(filename, "http:", NULL)) {\n        int err = read_ffserver_streams(oc, filename);\n        if (err < 0) {\n            print_error(filename, err);\n            ffmpeg_exit(1);\n        }\n    } else {\n        use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n        use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n        use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n        if (nb_input_files > 0) {\n            check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n                                         &input_has_subtitle);\n            if (!input_has_video)\n                use_video = 0;\n            if (!input_has_audio)\n                use_audio = 0;\n            if (!input_has_subtitle)\n                use_subtitle = 0;\n        }\n        if (audio_disable) {\n            use_audio = 0;\n        }\n        if (video_disable) {\n            use_video = 0;\n        }\n        if (subtitle_disable) {\n            use_subtitle = 0;\n        }\n        if (use_video) {\n            new_video_stream(oc, nb_output_files);\n        }\n        if (use_audio) {\n            new_audio_stream(oc, nb_output_files);\n        }\n        if (use_subtitle) {\n            new_subtitle_stream(oc, nb_output_files);\n        }\n        oc->timestamp = recording_timestamp;\n        for(; metadata_count>0; metadata_count--){\n            av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key,\n                                            metadata[metadata_count-1].value, 0);\n        }\n        av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n    }\n    output_files[nb_output_files++] = oc;\n    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n        if (!av_filename_number_test(oc->filename)) {\n            print_error(oc->filename, AVERROR_NUMEXPECTED);\n            ffmpeg_exit(1);\n        }\n    }\n    if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n        if (!file_overwrite &&\n            (strchr(filename, \':\') == NULL ||\n             filename[1] == \':\' ||\n             av_strstart(filename, "file:", NULL))) {\n            if (url_exist(filename)) {\n                if (!using_stdin) {\n                    fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n                    fflush(stderr);\n                    if (!read_yesno()) {\n                        fprintf(stderr, "Not overwriting - exiting\\n");\n                        ffmpeg_exit(1);\n                    }\n                }\n                else {\n                    fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n                    ffmpeg_exit(1);\n                }\n            }\n        }\n        if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {\n            print_error(filename, err);\n            ffmpeg_exit(1);\n        }\n    }\n    memset(ap, 0, sizeof(*ap));\n    if (av_set_parameters(oc, ap) < 0) {\n        fprintf(stderr, "%s: Invalid encoding parameters\\n",\n                oc->filename);\n        ffmpeg_exit(1);\n    }\n    oc->preload= (int)(mux_preload*AV_TIME_BASE);\n    oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n    oc->loop_output = loop_output;\n    oc->flags |= AVFMT_FLAG_NONBLOCK;\n    set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);\n    nb_streamid_map = 0;\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n    AVFormatContext *ic;\n    ic = av_malloc(sizeof(AVFormatContext));\n    if (!ic) return ic;\n    avformat_get_context_defaults(ic);\n    ic->av_class = &av_format_context_class;\n    return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+16);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&15) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,16,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(16,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n    char errbuf[128];\n    const char *errbuf_ptr = errbuf;\n    if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n        errbuf_ptr = strerror(AVUNERROR(err));\n    fprintf(stderr, "%s: %s\\n", filename, errbuf_ptr);\n}', 'int av_strerror(int errnum, char *errbuf, size_t errbuf_size)\n{\n    int ret = 0;\n    const char *errstr = NULL;\n    switch (errnum) {\n    case AVERROR_EOF:               errstr = "End of file"; break;\n    case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;\n    case AVERROR_NUMEXPECTED:       errstr = "Number syntax expected in filename"; break;\n    case AVERROR_PATCHWELCOME:      errstr = "Not yet implemented in FFmpeg, patches welcome"; break;\n    }\n    if (errstr) {\n        av_strlcpy(errbuf, errstr, errbuf_size);\n    } else {\n#if HAVE_STRERROR_R\n        ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);\n#else\n        ret = -1;\n#endif\n        if (ret < 0)\n            snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);\n    }\n    return ret;\n}']