libavcodec/decode.c:858: error: Null Dereference
  pointer `desc` last assigned on line 857 could be null and is dereferenced at line 858, column 9.

libavcodec/decode.c:843:1: start of procedure ff_get_format()
841. }
842. 
843. int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
     ^
844. {
845.     const AVPixFmtDescriptor *desc;

libavcodec/decode.c:853:10: 
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
              ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:17: Loop condition is true. Entering loop body
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                     ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:44: 
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                                                ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:17: Loop condition is true. Entering loop body
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                     ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:44: 
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                                                ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:17: Loop condition is true. Entering loop body
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                     ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:44: 
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                                                ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:853:17: Loop condition is false. Leaving loop
851. 
852.     // Find end of list.
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
                     ^
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);

libavcodec/decode.c:855:5: Taking false branch
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);
         ^
856.     // If a software format is available, it must be the last entry.
857.     desc = av_pix_fmt_desc_get(fmt[n - 1]);

libavcodec/decode.c:855:5: Loop condition is false. Leaving loop
853.     for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
854.     // Must contain at least one entry.
855.     av_assert0(n >= 1);
         ^
856.     // If a software format is available, it must be the last entry.
857.     desc = av_pix_fmt_desc_get(fmt[n - 1]);

libavcodec/decode.c:857:5: 
855.     av_assert0(n >= 1);
856.     // If a software format is available, it must be the last entry.
857.     desc = av_pix_fmt_desc_get(fmt[n - 1]);
         ^
858.     if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
859.         // No software format is available.

libavutil/pixdesc.c:1901:1: start of procedure av_pix_fmt_desc_get()
  1899. }
  1900. 
  1901. const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
        ^
  1902. {
  1903.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)

libavutil/pixdesc.c:1903:9: Taking false branch
  1901. const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
  1902. {
  1903.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
                ^
  1904.         return NULL;
  1905.     return &av_pix_fmt_descriptors[pix_fmt];

libavutil/pixdesc.c:1903:24: Taking true branch
  1901. const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
  1902. {
  1903.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
                               ^
  1904.         return NULL;
  1905.     return &av_pix_fmt_descriptors[pix_fmt];

libavutil/pixdesc.c:1904:9: 
  1902. {
  1903.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
  1904.         return NULL;
                ^
  1905.     return &av_pix_fmt_descriptors[pix_fmt];
  1906. }

libavutil/pixdesc.c:1906:1: return from a call to av_pix_fmt_desc_get
  1904.         return NULL;
  1905.     return &av_pix_fmt_descriptors[pix_fmt];
  1906. }
        ^
  1907. 
  1908. const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)

libavcodec/decode.c:858:9: 
856.     // If a software format is available, it must be the last entry.
857.     desc = av_pix_fmt_desc_get(fmt[n - 1]);
858.     if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
             ^
859.         // No software format is available.
860.     } else {

int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
{
    const AVPixFmtDescriptor *desc;
    enum AVPixelFormat *choices;
    enum AVPixelFormat ret, user_choice;
    const AVCodecHWConfigInternal *hw_config;
    const AVCodecHWConfig *config;
    int i, n, err;
    for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
    av_assert0(n >= 1);
    desc = av_pix_fmt_desc_get(fmt[n - 1]);
    if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
    } else {
        avctx->sw_pix_fmt = fmt[n - 1];
    }
    choices = av_malloc_array(n + 1, sizeof(*choices));
    if (!choices)
        return AV_PIX_FMT_NONE;
    memcpy(choices, fmt, (n + 1) * sizeof(*choices));
    for (;;) {
        hwaccel_uninit(avctx);
        user_choice = avctx->get_format(avctx, choices);
        if (user_choice == AV_PIX_FMT_NONE) {
            ret = AV_PIX_FMT_NONE;
            break;
        }
        desc = av_pix_fmt_desc_get(user_choice);
        if (!desc) {
            av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
                   "get_format() callback.\n");
            ret = AV_PIX_FMT_NONE;
            break;
        }
        av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
               desc->name);
        for (i = 0; i < n; i++) {
            if (choices[i] == user_choice)
                break;
        }
        if (i == n) {
            av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
                   "%s not in possible list.\n", desc->name);
            break;
        }
        if (avctx->codec->hw_configs) {
            for (i = 0;; i++) {
                hw_config = avctx->codec->hw_configs[i];
                if (!hw_config)
                    break;
                if (hw_config->public.pix_fmt == user_choice)
                    break;
            }
        } else {
            hw_config = NULL;
        }
        if (!hw_config) {
            ret = user_choice;
            break;
        }
        config = &hw_config->public;
        if (config->methods &
            AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
            avctx->hw_frames_ctx) {
            const AVHWFramesContext *frames_ctx =
                (AVHWFramesContext*)avctx->hw_frames_ctx->data;
            if (frames_ctx->format != user_choice) {
                av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
                       "does not match the format of the provided frames "
                       "context.\n", desc->name);
                goto try_again;
            }
        } else if (config->methods &
                   AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
                   avctx->hw_device_ctx) {
            const AVHWDeviceContext *device_ctx =
                (AVHWDeviceContext*)avctx->hw_device_ctx->data;
            if (device_ctx->type != config->device_type) {
                av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
                       "does not match the type of the provided device "
                       "context.\n", desc->name);
                goto try_again;
            }
        } else if (config->methods &
                   AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
        } else if (config->methods &
                   AV_CODEC_HW_CONFIG_METHOD_AD_HOC) {
        } else {
            av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
                   "missing configuration.\n", desc->name);
            goto try_again;
        }
        if (hw_config->hwaccel) {
            av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
                   "initialisation.\n", desc->name);
            err = hwaccel_init(avctx, hw_config);
            if (err < 0)
                goto try_again;
        }
        ret = user_choice;
        break;
    try_again:
        av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
               "get_format() without it.\n", desc->name);
        for (i = 0; i < n; i++) {
            if (choices[i] == user_choice)
                break;
        }
        for (; i + 1 < n; i++)
            choices[i] = choices[i + 1];
        --n;
    }
    av_freep(&choices);
    return ret;
}
['int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)\n{\n    const AVPixFmtDescriptor *desc;\n    enum AVPixelFormat *choices;\n    enum AVPixelFormat ret, user_choice;\n    const AVCodecHWConfigInternal *hw_config;\n    const AVCodecHWConfig *config;\n    int i, n, err;\n    for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);\n    av_assert0(n >= 1);\n    desc = av_pix_fmt_desc_get(fmt[n - 1]);\n    if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {\n    } else {\n        avctx->sw_pix_fmt = fmt[n - 1];\n    }\n    choices = av_malloc_array(n + 1, sizeof(*choices));\n    if (!choices)\n        return AV_PIX_FMT_NONE;\n    memcpy(choices, fmt, (n + 1) * sizeof(*choices));\n    for (;;) {\n        hwaccel_uninit(avctx);\n        user_choice = avctx->get_format(avctx, choices);\n        if (user_choice == AV_PIX_FMT_NONE) {\n            ret = AV_PIX_FMT_NONE;\n            break;\n        }\n        desc = av_pix_fmt_desc_get(user_choice);\n        if (!desc) {\n            av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "\n                   "get_format() callback.\\n");\n            ret = AV_PIX_FMT_NONE;\n            break;\n        }\n        av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\\n",\n               desc->name);\n        for (i = 0; i < n; i++) {\n            if (choices[i] == user_choice)\n                break;\n        }\n        if (i == n) {\n            av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "\n                   "%s not in possible list.\\n", desc->name);\n            break;\n        }\n        if (avctx->codec->hw_configs) {\n            for (i = 0;; i++) {\n                hw_config = avctx->codec->hw_configs[i];\n                if (!hw_config)\n                    break;\n                if (hw_config->public.pix_fmt == user_choice)\n                    break;\n            }\n        } else {\n            hw_config = NULL;\n        }\n        if (!hw_config) {\n            ret = user_choice;\n            break;\n        }\n        config = &hw_config->public;\n        if (config->methods &\n            AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&\n            avctx->hw_frames_ctx) {\n            const AVHWFramesContext *frames_ctx =\n                (AVHWFramesContext*)avctx->hw_frames_ctx->data;\n            if (frames_ctx->format != user_choice) {\n                av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "\n                       "does not match the format of the provided frames "\n                       "context.\\n", desc->name);\n                goto try_again;\n            }\n        } else if (config->methods &\n                   AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&\n                   avctx->hw_device_ctx) {\n            const AVHWDeviceContext *device_ctx =\n                (AVHWDeviceContext*)avctx->hw_device_ctx->data;\n            if (device_ctx->type != config->device_type) {\n                av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "\n                       "does not match the type of the provided device "\n                       "context.\\n", desc->name);\n                goto try_again;\n            }\n        } else if (config->methods &\n                   AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {\n        } else if (config->methods &\n                   AV_CODEC_HW_CONFIG_METHOD_AD_HOC) {\n        } else {\n            av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "\n                   "missing configuration.\\n", desc->name);\n            goto try_again;\n        }\n        if (hw_config->hwaccel) {\n            av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "\n                   "initialisation.\\n", desc->name);\n            err = hwaccel_init(avctx, hw_config);\n            if (err < 0)\n                goto try_again;\n        }\n        ret = user_choice;\n        break;\n    try_again:\n        av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "\n               "get_format() without it.\\n", desc->name);\n        for (i = 0; i < n; i++) {\n            if (choices[i] == user_choice)\n                break;\n        }\n        for (; i + 1 < n; i++)\n            choices[i] = choices[i + 1];\n        --n;\n    }\n    av_freep(&choices);\n    return ret;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n        return NULL;\n    return &av_pix_fmt_descriptors[pix_fmt];\n}']