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

libavcodec/xwdenc.c:33:1: start of procedure xwd_encode_frame()
31. #define WINDOW_NAME_SIZE    11
32. 
33. static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
    ^
34.                             const AVFrame *p, int *got_packet)
35. {

libavcodec/xwdenc.c:36:5: 
34.                             const AVFrame *p, int *got_packet)
35. {
36.     enum AVPixelFormat pix_fmt = avctx->pix_fmt;
        ^
37.     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
38.     uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;

libavcodec/xwdenc.c:37:5: 
35. {
36.     enum AVPixelFormat pix_fmt = avctx->pix_fmt;
37.     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
        ^
38.     uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
39.     uint32_t rgb[3] = { 0 }, bitorder = 0;

libavutil/pixdesc.c:1685:1: start of procedure av_pix_fmt_desc_get()
  1683. }
  1684. 
  1685. const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
        ^
  1686. {
  1687.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)

libavutil/pixdesc.c:1687:9: Taking false branch
  1685. const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
  1686. {
  1687.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
                ^
  1688.         return NULL;
  1689.     return &av_pix_fmt_descriptors[pix_fmt];

libavutil/pixdesc.c:1687:24: Taking true branch
  1685. const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
  1686. {
  1687.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
                               ^
  1688.         return NULL;
  1689.     return &av_pix_fmt_descriptors[pix_fmt];

libavutil/pixdesc.c:1688:9: 
  1686. {
  1687.     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
  1688.         return NULL;
                ^
  1689.     return &av_pix_fmt_descriptors[pix_fmt];
  1690. }

libavutil/pixdesc.c:1690:1: return from a call to av_pix_fmt_desc_get
  1688.         return NULL;
  1689.     return &av_pix_fmt_descriptors[pix_fmt];
  1690. }
        ^
  1691. 
  1692. const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)

libavcodec/xwdenc.c:38:5: 
36.     enum AVPixelFormat pix_fmt = avctx->pix_fmt;
37.     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
38.     uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
        ^
39.     uint32_t rgb[3] = { 0 }, bitorder = 0;
40.     uint32_t header_size;

libavcodec/xwdenc.c:39:5: 
37.     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
38.     uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
39.     uint32_t rgb[3] = { 0 }, bitorder = 0;
        ^
40.     uint32_t header_size;
41.     int i, out_size, ret;

libavcodec/xwdenc.c:44:5: Skipping av_get_bits_per_pixel(): empty list of specs
42.     uint8_t *ptr, *buf;
43. 
44.     pixdepth = av_get_bits_per_pixel(desc);
        ^
45.     if (desc->flags & AV_PIX_FMT_FLAG_BE)
46.         be = 1;

libavcodec/xwdenc.c:45:9: 
43. 
44.     pixdepth = av_get_bits_per_pixel(desc);
45.     if (desc->flags & AV_PIX_FMT_FLAG_BE)
            ^
46.         be = 1;
47.     switch (pix_fmt) {

static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                            const AVFrame *p, int *got_packet)
{
    enum AVPixelFormat pix_fmt = avctx->pix_fmt;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
    uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
    uint32_t rgb[3] = { 0 }, bitorder = 0;
    uint32_t header_size;
    int i, out_size, ret;
    uint8_t *ptr, *buf;
    pixdepth = av_get_bits_per_pixel(desc);
    if (desc->flags & AV_PIX_FMT_FLAG_BE)
        be = 1;
    switch (pix_fmt) {
    case AV_PIX_FMT_ARGB:
    case AV_PIX_FMT_BGRA:
    case AV_PIX_FMT_RGBA:
    case AV_PIX_FMT_ABGR:
        if (pix_fmt == AV_PIX_FMT_ARGB ||
            pix_fmt == AV_PIX_FMT_ABGR)
            be = 1;
        if (pix_fmt == AV_PIX_FMT_ABGR ||
            pix_fmt == AV_PIX_FMT_RGBA) {
            rgb[0] = 0xFF;
            rgb[1] = 0xFF00;
            rgb[2] = 0xFF0000;
        } else {
            rgb[0] = 0xFF0000;
            rgb[1] = 0xFF00;
            rgb[2] = 0xFF;
        }
        bpp      = 32;
        pixdepth = 24;
        vclass   = XWD_TRUE_COLOR;
        bpad     = 32;
        break;
    case AV_PIX_FMT_BGR24:
    case AV_PIX_FMT_RGB24:
        if (pix_fmt == AV_PIX_FMT_RGB24)
            be = 1;
        bpp      = 24;
        vclass   = XWD_TRUE_COLOR;
        bpad     = 32;
        rgb[0]   = 0xFF0000;
        rgb[1]   = 0xFF00;
        rgb[2]   = 0xFF;
        break;
    case AV_PIX_FMT_RGB565LE:
    case AV_PIX_FMT_RGB565BE:
    case AV_PIX_FMT_BGR565LE:
    case AV_PIX_FMT_BGR565BE:
        if (pix_fmt == AV_PIX_FMT_BGR565LE ||
            pix_fmt == AV_PIX_FMT_BGR565BE) {
            rgb[0] = 0x1F;
            rgb[1] = 0x7E0;
            rgb[2] = 0xF800;
        } else {
            rgb[0] = 0xF800;
            rgb[1] = 0x7E0;
            rgb[2] = 0x1F;
        }
        bpp      = 16;
        vclass   = XWD_TRUE_COLOR;
        bpad     = 16;
        break;
    case AV_PIX_FMT_RGB555LE:
    case AV_PIX_FMT_RGB555BE:
    case AV_PIX_FMT_BGR555LE:
    case AV_PIX_FMT_BGR555BE:
        if (pix_fmt == AV_PIX_FMT_BGR555LE ||
            pix_fmt == AV_PIX_FMT_BGR555BE) {
            rgb[0] = 0x1F;
            rgb[1] = 0x3E0;
            rgb[2] = 0x7C00;
        } else {
            rgb[0] = 0x7C00;
            rgb[1] = 0x3E0;
            rgb[2] = 0x1F;
        }
        bpp      = 16;
        vclass   = XWD_TRUE_COLOR;
        bpad     = 16;
        break;
    case AV_PIX_FMT_RGB8:
    case AV_PIX_FMT_BGR8:
    case AV_PIX_FMT_RGB4_BYTE:
    case AV_PIX_FMT_BGR4_BYTE:
    case AV_PIX_FMT_PAL8:
        bpp      = 8;
        vclass   = XWD_PSEUDO_COLOR;
        bpad     = 8;
        ncolors  = 256;
        break;
    case AV_PIX_FMT_MONOWHITE:
        be       = 1;
        bitorder = 1;
        bpp      = 1;
        bpad     = 8;
        vclass   = XWD_STATIC_GRAY;
        break;
    default:
        av_log(avctx, AV_LOG_INFO, "unsupported pixel format\n");
        return AVERROR(EINVAL);
    }
    lsize       = FFALIGN(bpp * avctx->width, bpad) / 8;
    header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE;
    out_size    = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize;
    if ((ret = ff_alloc_packet(pkt, out_size)) < 0) {
        av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
        return ret;
    }
    buf = pkt->data;
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
    avctx->coded_frame->key_frame = 1;
    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
    bytestream_put_be32(&buf, header_size);
    bytestream_put_be32(&buf, XWD_VERSION);
    bytestream_put_be32(&buf, XWD_Z_PIXMAP);
    bytestream_put_be32(&buf, pixdepth);
    bytestream_put_be32(&buf, avctx->width);
    bytestream_put_be32(&buf, avctx->height);
    bytestream_put_be32(&buf, 0);
    bytestream_put_be32(&buf, be);
    bytestream_put_be32(&buf, 32);
    bytestream_put_be32(&buf, bitorder);
    bytestream_put_be32(&buf, bpad);
    bytestream_put_be32(&buf, bpp);
    bytestream_put_be32(&buf, lsize);
    bytestream_put_be32(&buf, vclass);
    bytestream_put_be32(&buf, rgb[0]);
    bytestream_put_be32(&buf, rgb[1]);
    bytestream_put_be32(&buf, rgb[2]);
    bytestream_put_be32(&buf, 8);
    bytestream_put_be32(&buf, ncolors);
    bytestream_put_be32(&buf, ncolors);
    bytestream_put_be32(&buf, avctx->width);
    bytestream_put_be32(&buf, avctx->height);
    bytestream_put_be32(&buf, 0);
    bytestream_put_be32(&buf, 0);
    bytestream_put_be32(&buf, 0);
    bytestream_put_buffer(&buf, WINDOW_NAME, WINDOW_NAME_SIZE);
    for (i = 0; i < ncolors; i++) {
        uint32_t val;
        uint8_t red, green, blue;
        val   = AV_RN32A(p->data[1] + i * 4);
        red   = (val >> 16) & 0xFF;
        green = (val >>  8) & 0xFF;
        blue  =  val        & 0xFF;
        bytestream_put_be32(&buf, i);
        bytestream_put_be16(&buf, red   << 8);
        bytestream_put_be16(&buf, green << 8);
        bytestream_put_be16(&buf, blue  << 8);
        bytestream_put_byte(&buf, 0x7);
        bytestream_put_byte(&buf, 0);
    }
    ptr = p->data[0];
    for (i = 0; i < avctx->height; i++) {
        bytestream_put_buffer(&buf, ptr, lsize);
        ptr += p->linesize[0];
    }
    pkt->flags |= AV_PKT_FLAG_KEY;
    *got_packet = 1;
    return 0;
}
['static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,\n                            const AVFrame *p, int *got_packet)\n{\n    enum AVPixelFormat pix_fmt = avctx->pix_fmt;\n    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);\n    uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;\n    uint32_t rgb[3] = { 0 }, bitorder = 0;\n    uint32_t header_size;\n    int i, out_size, ret;\n    uint8_t *ptr, *buf;\n    pixdepth = av_get_bits_per_pixel(desc);\n    if (desc->flags & AV_PIX_FMT_FLAG_BE)\n        be = 1;\n    switch (pix_fmt) {\n    case AV_PIX_FMT_ARGB:\n    case AV_PIX_FMT_BGRA:\n    case AV_PIX_FMT_RGBA:\n    case AV_PIX_FMT_ABGR:\n        if (pix_fmt == AV_PIX_FMT_ARGB ||\n            pix_fmt == AV_PIX_FMT_ABGR)\n            be = 1;\n        if (pix_fmt == AV_PIX_FMT_ABGR ||\n            pix_fmt == AV_PIX_FMT_RGBA) {\n            rgb[0] = 0xFF;\n            rgb[1] = 0xFF00;\n            rgb[2] = 0xFF0000;\n        } else {\n            rgb[0] = 0xFF0000;\n            rgb[1] = 0xFF00;\n            rgb[2] = 0xFF;\n        }\n        bpp      = 32;\n        pixdepth = 24;\n        vclass   = XWD_TRUE_COLOR;\n        bpad     = 32;\n        break;\n    case AV_PIX_FMT_BGR24:\n    case AV_PIX_FMT_RGB24:\n        if (pix_fmt == AV_PIX_FMT_RGB24)\n            be = 1;\n        bpp      = 24;\n        vclass   = XWD_TRUE_COLOR;\n        bpad     = 32;\n        rgb[0]   = 0xFF0000;\n        rgb[1]   = 0xFF00;\n        rgb[2]   = 0xFF;\n        break;\n    case AV_PIX_FMT_RGB565LE:\n    case AV_PIX_FMT_RGB565BE:\n    case AV_PIX_FMT_BGR565LE:\n    case AV_PIX_FMT_BGR565BE:\n        if (pix_fmt == AV_PIX_FMT_BGR565LE ||\n            pix_fmt == AV_PIX_FMT_BGR565BE) {\n            rgb[0] = 0x1F;\n            rgb[1] = 0x7E0;\n            rgb[2] = 0xF800;\n        } else {\n            rgb[0] = 0xF800;\n            rgb[1] = 0x7E0;\n            rgb[2] = 0x1F;\n        }\n        bpp      = 16;\n        vclass   = XWD_TRUE_COLOR;\n        bpad     = 16;\n        break;\n    case AV_PIX_FMT_RGB555LE:\n    case AV_PIX_FMT_RGB555BE:\n    case AV_PIX_FMT_BGR555LE:\n    case AV_PIX_FMT_BGR555BE:\n        if (pix_fmt == AV_PIX_FMT_BGR555LE ||\n            pix_fmt == AV_PIX_FMT_BGR555BE) {\n            rgb[0] = 0x1F;\n            rgb[1] = 0x3E0;\n            rgb[2] = 0x7C00;\n        } else {\n            rgb[0] = 0x7C00;\n            rgb[1] = 0x3E0;\n            rgb[2] = 0x1F;\n        }\n        bpp      = 16;\n        vclass   = XWD_TRUE_COLOR;\n        bpad     = 16;\n        break;\n    case AV_PIX_FMT_RGB8:\n    case AV_PIX_FMT_BGR8:\n    case AV_PIX_FMT_RGB4_BYTE:\n    case AV_PIX_FMT_BGR4_BYTE:\n    case AV_PIX_FMT_PAL8:\n        bpp      = 8;\n        vclass   = XWD_PSEUDO_COLOR;\n        bpad     = 8;\n        ncolors  = 256;\n        break;\n    case AV_PIX_FMT_MONOWHITE:\n        be       = 1;\n        bitorder = 1;\n        bpp      = 1;\n        bpad     = 8;\n        vclass   = XWD_STATIC_GRAY;\n        break;\n    default:\n        av_log(avctx, AV_LOG_INFO, "unsupported pixel format\\n");\n        return AVERROR(EINVAL);\n    }\n    lsize       = FFALIGN(bpp * avctx->width, bpad) / 8;\n    header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE;\n    out_size    = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize;\n    if ((ret = ff_alloc_packet(pkt, out_size)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "output buffer too small\\n");\n        return ret;\n    }\n    buf = pkt->data;\n#if FF_API_CODED_FRAME\nFF_DISABLE_DEPRECATION_WARNINGS\n    avctx->coded_frame->key_frame = 1;\n    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n    bytestream_put_be32(&buf, header_size);\n    bytestream_put_be32(&buf, XWD_VERSION);\n    bytestream_put_be32(&buf, XWD_Z_PIXMAP);\n    bytestream_put_be32(&buf, pixdepth);\n    bytestream_put_be32(&buf, avctx->width);\n    bytestream_put_be32(&buf, avctx->height);\n    bytestream_put_be32(&buf, 0);\n    bytestream_put_be32(&buf, be);\n    bytestream_put_be32(&buf, 32);\n    bytestream_put_be32(&buf, bitorder);\n    bytestream_put_be32(&buf, bpad);\n    bytestream_put_be32(&buf, bpp);\n    bytestream_put_be32(&buf, lsize);\n    bytestream_put_be32(&buf, vclass);\n    bytestream_put_be32(&buf, rgb[0]);\n    bytestream_put_be32(&buf, rgb[1]);\n    bytestream_put_be32(&buf, rgb[2]);\n    bytestream_put_be32(&buf, 8);\n    bytestream_put_be32(&buf, ncolors);\n    bytestream_put_be32(&buf, ncolors);\n    bytestream_put_be32(&buf, avctx->width);\n    bytestream_put_be32(&buf, avctx->height);\n    bytestream_put_be32(&buf, 0);\n    bytestream_put_be32(&buf, 0);\n    bytestream_put_be32(&buf, 0);\n    bytestream_put_buffer(&buf, WINDOW_NAME, WINDOW_NAME_SIZE);\n    for (i = 0; i < ncolors; i++) {\n        uint32_t val;\n        uint8_t red, green, blue;\n        val   = AV_RN32A(p->data[1] + i * 4);\n        red   = (val >> 16) & 0xFF;\n        green = (val >>  8) & 0xFF;\n        blue  =  val        & 0xFF;\n        bytestream_put_be32(&buf, i);\n        bytestream_put_be16(&buf, red   << 8);\n        bytestream_put_be16(&buf, green << 8);\n        bytestream_put_be16(&buf, blue  << 8);\n        bytestream_put_byte(&buf, 0x7);\n        bytestream_put_byte(&buf, 0);\n    }\n    ptr = p->data[0];\n    for (i = 0; i < avctx->height; i++) {\n        bytestream_put_buffer(&buf, ptr, lsize);\n        ptr += p->linesize[0];\n    }\n    pkt->flags |= AV_PKT_FLAG_KEY;\n    *got_packet = 1;\n    return 0;\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}']