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

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

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

ffmpeg.c:3716:9: 
3714. 
3715.     if (!strcmp(filename, "-"))
3716.         filename = "pipe:";
              ^
3717. 
3718.     oc = avformat_alloc_context();

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

libavformat/options.c:127:1: start of procedure avformat_alloc_context()
  125. }
  126. 
  127. AVFormatContext *avformat_alloc_context(void)
       ^
  128. {
  129.     AVFormatContext *ic;

libavformat/options.c:130:5: 
  128. {
  129.     AVFormatContext *ic;
  130.     ic = av_malloc(sizeof(AVFormatContext));
           ^
  131.     if (!ic) return ic;
  132.     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(size_t size)
        ^
    65. {
    66.     void *ptr = NULL;

libavutil/mem.c:66:5: 
    64. void *av_malloc(size_t 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-32) )
               ^
    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,32,size))
                ^
    84.         ptr = NULL;
    85. #elif HAVE_MEMALIGN

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

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

libavformat/options.c:131:10: Taking true branch
  129.     AVFormatContext *ic;
  130.     ic = av_malloc(sizeof(AVFormatContext));
  131.     if (!ic) return ic;
                ^
  132.     avformat_get_context_defaults(ic);
  133.     return ic;

libavformat/options.c:131:14: 
  129.     AVFormatContext *ic;
  130.     ic = av_malloc(sizeof(AVFormatContext));
  131.     if (!ic) return ic;
                    ^
  132.     avformat_get_context_defaults(ic);
  133.     return ic;

libavformat/options.c:134:1: return from a call to avformat_alloc_context
  132.     avformat_get_context_defaults(ic);
  133.     return ic;
  134. }
       ^
  135. 
  136. const AVClass *avformat_get_class(void)

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

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

cmdutils.c:435:1: start of procedure print_error()
  433. }
  434. 
  435. void print_error(const char *filename, int err)
       ^
  436. {
  437.     char errbuf[128];

cmdutils.c:438:5: 
  436. {
  437.     char errbuf[128];
  438.     const char *errbuf_ptr = errbuf;
           ^
  439. 
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)

cmdutils.c:440:9: Taking true branch
  438.     const char *errbuf_ptr = errbuf;
  439. 
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
               ^
  441.         errbuf_ptr = strerror(AVUNERROR(err));
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);

cmdutils.c:441:9: Skipping strerror(): method has no implementation
  439. 
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
  441.         errbuf_ptr = strerror(AVUNERROR(err));
               ^
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
  443. }

cmdutils.c:442:5: Skipping av_log(): empty list of specs
  440.     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
  441.         errbuf_ptr = strerror(AVUNERROR(err));
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
           ^
  443. }
  444. 

cmdutils.c:443:1: return from a call to print_error
  441.         errbuf_ptr = strerror(AVUNERROR(err));
  442.     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
  443. }
       ^
  444. 
  445. static int warned_cfg = 0;

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

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

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

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

ffmpeg.c:3727:13: 
3725.         file_oformat = av_guess_format(last_asked_format, NULL, NULL);
3726.         if (!file_oformat) {
3727.             fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
                  ^
3728.             exit_program(1);
3729.         }

ffmpeg.c:3728:13: Skipping exit_program(): empty list of specs
3726.         if (!file_oformat) {
3727.             fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
3728.             exit_program(1);
                  ^
3729.         }
3730.         last_asked_format = NULL;

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

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

static void opt_output_file(void *optctx, const char *filename)
{
    AVFormatContext *oc;
    int err, use_video, use_audio, use_subtitle, use_data;
    int input_has_video, input_has_audio, input_has_subtitle, input_has_data;
    AVOutputFormat *file_oformat;
    if (!strcmp(filename, "-"))
        filename = "pipe:";
    oc = avformat_alloc_context();
    if (!oc) {
        print_error(filename, AVERROR(ENOMEM));
        exit_program(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);
            exit_program(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);
            exit_program(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_avserver_streams(oc, filename);
        if (err < 0) {
            print_error(filename, err);
            exit_program(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;
        use_data = data_stream_copy ||  data_codec_name;
        check_inputs(&input_has_video,
                     &input_has_audio,
                     &input_has_subtitle,
                     &input_has_data);
        if (!input_has_video)
            use_video = 0;
        if (!input_has_audio)
            use_audio = 0;
        if (!input_has_subtitle)
            use_subtitle = 0;
        if (!input_has_data)
            use_data = 0;
        if (audio_disable)    use_audio    = 0;
        if (video_disable)    use_video    = 0;
        if (subtitle_disable) use_subtitle = 0;
        if (data_disable)     use_data     = 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);
        if (use_data)     new_data_stream(oc, nb_output_files);
        av_dict_copy(&oc->metadata, metadata, 0);
        av_dict_free(&metadata);
    }
    av_dict_copy(&output_opts[nb_output_files], format_opts, 0);
    output_files[nb_output_files++] = oc;
    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
        if (!av_filename_number_test(oc->filename)) {
            print_error(oc->filename, AVERROR(EINVAL));
            exit_program(1);
        }
    }
    if (!(oc->oformat->flags & AVFMT_NOFILE)) {
        if (!file_overwrite &&
            (strchr(filename, ':') == NULL ||
             filename[1] == ':' ||
             av_strstart(filename, "file:", NULL))) {
            if (avio_check(filename, 0) == 0) {
                if (!using_stdin) {
                    fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
                    fflush(stderr);
                    if (!read_yesno()) {
                        fprintf(stderr, "Not overwriting - exiting\n");
                        exit_program(1);
                    }
                }
                else {
                    fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
                    exit_program(1);
                }
            }
        }
        if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
            print_error(filename, err);
            exit_program(1);
        }
    }
    oc->preload= (int)(mux_preload*AV_TIME_BASE);
    oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
    if (loop_output >= 0) {
        av_log(NULL, AV_LOG_WARNING, "-loop_output is deprecated, use -loop\n");
        oc->loop_output = loop_output;
    }
    oc->flags |= AVFMT_FLAG_NONBLOCK;
    frame_rate    = (AVRational){0, 0};
    frame_width   = 0;
    frame_height  = 0;
    audio_sample_rate = 0;
    audio_channels    = 0;
    audio_sample_fmt  = AV_SAMPLE_FMT_NONE;
    av_freep(&forced_key_frames);
    uninit_opts();
    init_opts();
}
['static void opt_output_file(void *optctx, const char *filename)\n{\n    AVFormatContext *oc;\n    int err, use_video, use_audio, use_subtitle, use_data;\n    int input_has_video, input_has_audio, input_has_subtitle, input_has_data;\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        exit_program(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            exit_program(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            exit_program(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_avserver_streams(oc, filename);\n        if (err < 0) {\n            print_error(filename, err);\n            exit_program(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        use_data = data_stream_copy ||  data_codec_name;\n        check_inputs(&input_has_video,\n                     &input_has_audio,\n                     &input_has_subtitle,\n                     &input_has_data);\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        if (!input_has_data)\n            use_data = 0;\n        if (audio_disable)    use_audio    = 0;\n        if (video_disable)    use_video    = 0;\n        if (subtitle_disable) use_subtitle = 0;\n        if (data_disable)     use_data     = 0;\n        if (use_video)    new_video_stream(oc, nb_output_files);\n        if (use_audio)    new_audio_stream(oc, nb_output_files);\n        if (use_subtitle) new_subtitle_stream(oc, nb_output_files);\n        if (use_data)     new_data_stream(oc, nb_output_files);\n        av_dict_copy(&oc->metadata, metadata, 0);\n        av_dict_free(&metadata);\n    }\n    av_dict_copy(&output_opts[nb_output_files], format_opts, 0);\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(EINVAL));\n            exit_program(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 (avio_check(filename, 0) == 0) {\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                        exit_program(1);\n                    }\n                }\n                else {\n                    fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n                    exit_program(1);\n                }\n            }\n        }\n        if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {\n            print_error(filename, err);\n            exit_program(1);\n        }\n    }\n    oc->preload= (int)(mux_preload*AV_TIME_BASE);\n    oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n    if (loop_output >= 0) {\n        av_log(NULL, AV_LOG_WARNING, "-loop_output is deprecated, use -loop\\n");\n        oc->loop_output = loop_output;\n    }\n    oc->flags |= AVFMT_FLAG_NONBLOCK;\n    frame_rate    = (AVRational){0, 0};\n    frame_width   = 0;\n    frame_height  = 0;\n    audio_sample_rate = 0;\n    audio_channels    = 0;\n    audio_sample_fmt  = AV_SAMPLE_FMT_NONE;\n    av_freep(&forced_key_frames);\n    uninit_opts();\n    init_opts();\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    return ic;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-32) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+32);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&31) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,32,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(32,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    av_log(NULL, AV_LOG_ERROR, "%s: %s\\n", filename, errbuf_ptr);\n}']