libavcodec/dvbsubdec.c:934: error: Null Dereference
  pointer `clut` last assigned on line 932 could be null and is dereferenced by call to `memcpy()` at line 934, column 9.

libavcodec/dvbsubdec.c:903:1: start of procedure dvbsub_parse_clut_segment()
901. }
902. 
903. static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
     ^
904.                                         const uint8_t *buf, int buf_size)
905. {

libavcodec/dvbsubdec.c:906:5: 
904.                                         const uint8_t *buf, int buf_size)
905. {
906.     DVBSubContext *ctx = avctx->priv_data;
         ^
907. 
908.     const uint8_t *buf_end = buf + buf_size;

libavcodec/dvbsubdec.c:908:5: 
906.     DVBSubContext *ctx = avctx->priv_data;
907. 
908.     const uint8_t *buf_end = buf + buf_size;
         ^
909.     int i, clut_id;
910.     DVBSubCLUT *clut;

libavcodec/dvbsubdec.c:917:10: 
915.     av_dlog(avctx, "DVB clut packet:\n");
916. 
917.     for (i=0; i < buf_size; i++) {
              ^
918.         av_dlog(avctx, "%02x ", buf[i]);
919.         if (i % 16 == 15)

libavcodec/dvbsubdec.c:917:15: Loop condition is false. Leaving loop
915.     av_dlog(avctx, "DVB clut packet:\n");
916. 
917.     for (i=0; i < buf_size; i++) {
                   ^
918.         av_dlog(avctx, "%02x ", buf[i]);
919.         if (i % 16 == 15)

libavcodec/dvbsubdec.c:923:9: Taking false branch
921.     }
922. 
923.     if (i % 16)
             ^
924.         av_dlog(avctx, "\n");
925. 

libavcodec/dvbsubdec.c:926:5: 
924.         av_dlog(avctx, "\n");
925. 
926.     clut_id = *buf++;
         ^
927.     buf += 1;
928. 

libavcodec/dvbsubdec.c:927:5: 
925. 
926.     clut_id = *buf++;
927.     buf += 1;
         ^
928. 
929.     clut = get_clut(ctx, clut_id);

libavcodec/dvbsubdec.c:929:5: 
927.     buf += 1;
928. 
929.     clut = get_clut(ctx, clut_id);
         ^
930. 
931.     if (!clut) {

libavcodec/dvbsubdec.c:253:1: start of procedure get_clut()
  251. }
  252. 
  253. static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
       ^
  254. {
  255.     DVBSubCLUT *ptr = ctx->clut_list;

libavcodec/dvbsubdec.c:255:5: 
  253. static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
  254. {
  255.     DVBSubCLUT *ptr = ctx->clut_list;
           ^
  256. 
  257.     while (ptr && ptr->id != clut_id) {

libavcodec/dvbsubdec.c:257:12: Loop condition is true. Entering loop body
  255.     DVBSubCLUT *ptr = ctx->clut_list;
  256. 
  257.     while (ptr && ptr->id != clut_id) {
                  ^
  258.         ptr = ptr->next;
  259.     }

libavcodec/dvbsubdec.c:257:19: Loop condition is true. Entering loop body
  255.     DVBSubCLUT *ptr = ctx->clut_list;
  256. 
  257.     while (ptr && ptr->id != clut_id) {
                         ^
  258.         ptr = ptr->next;
  259.     }

libavcodec/dvbsubdec.c:258:9: 
  256. 
  257.     while (ptr && ptr->id != clut_id) {
  258.         ptr = ptr->next;
               ^
  259.     }
  260. 

libavcodec/dvbsubdec.c:257:12: Loop condition is true. Entering loop body
  255.     DVBSubCLUT *ptr = ctx->clut_list;
  256. 
  257.     while (ptr && ptr->id != clut_id) {
                  ^
  258.         ptr = ptr->next;
  259.     }

libavcodec/dvbsubdec.c:257:19: Loop condition is true. Entering loop body
  255.     DVBSubCLUT *ptr = ctx->clut_list;
  256. 
  257.     while (ptr && ptr->id != clut_id) {
                         ^
  258.         ptr = ptr->next;
  259.     }

libavcodec/dvbsubdec.c:258:9: 
  256. 
  257.     while (ptr && ptr->id != clut_id) {
  258.         ptr = ptr->next;
               ^
  259.     }
  260. 

libavcodec/dvbsubdec.c:257:12: Loop condition is false. Leaving loop
  255.     DVBSubCLUT *ptr = ctx->clut_list;
  256. 
  257.     while (ptr && ptr->id != clut_id) {
                  ^
  258.         ptr = ptr->next;
  259.     }

libavcodec/dvbsubdec.c:261:5: 
  259.     }
  260. 
  261.     return ptr;
           ^
  262. }
  263. 

libavcodec/dvbsubdec.c:262:1: return from a call to get_clut
  260. 
  261.     return ptr;
  262. }
       ^
  263. 
  264. static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)

libavcodec/dvbsubdec.c:931:10: Taking true branch
929.     clut = get_clut(ctx, clut_id);
930. 
931.     if (!clut) {
              ^
932.         clut = av_malloc(sizeof(DVBSubCLUT));
933. 

libavcodec/dvbsubdec.c:932:9: 
930. 
931.     if (!clut) {
932.         clut = av_malloc(sizeof(DVBSubCLUT));
             ^
933. 
934.         memcpy(clut, &default_clut, sizeof(DVBSubCLUT));

libavutil/mem.c:61:1: start of procedure av_malloc()
  59.  * linker will do it automatically. */
  60. 
  61. void *av_malloc(size_t size)
      ^
  62. {
  63.     void *ptr = NULL;

libavutil/mem.c:63:5: 
  61. void *av_malloc(size_t size)
  62. {
  63.     void *ptr = NULL;
          ^
  64. #if CONFIG_MEMALIGN_HACK
  65.     long diff;

libavutil/mem.c:69:9: Taking false branch
  67. 
  68.     /* let's disallow possibly ambiguous cases */
  69.     if (size > (INT_MAX - 32) || !size)
              ^
  70.         return NULL;
  71. 

libavutil/mem.c:69:35: Taking false branch
  67. 
  68.     /* let's disallow possibly ambiguous cases */
  69.     if (size > (INT_MAX - 32) || !size)
                                        ^
  70.         return NULL;
  71. 

libavutil/mem.c:80:9: Taking true branch
  78.     ((char *)ptr)[-1] = diff;
  79. #elif HAVE_POSIX_MEMALIGN
  80.     if (posix_memalign(&ptr, 32, size))
              ^
  81.         ptr = NULL;
  82. #elif HAVE_ALIGNED_MALLOC

libavutil/mem.c:81:9: 
  79. #elif HAVE_POSIX_MEMALIGN
  80.     if (posix_memalign(&ptr, 32, size))
  81.         ptr = NULL;
              ^
  82. #elif HAVE_ALIGNED_MALLOC
  83.     ptr = _aligned_malloc(size, 32);

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

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

libavcodec/dvbsubdec.c:934:9: 
932.         clut = av_malloc(sizeof(DVBSubCLUT));
933. 
934.         memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
             ^
935. 
936.         clut->id = clut_id;

static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
                                        const uint8_t *buf, int buf_size)
{
    DVBSubContext *ctx = avctx->priv_data;
    const uint8_t *buf_end = buf + buf_size;
    int i, clut_id;
    DVBSubCLUT *clut;
    int entry_id, depth , full_range;
    int y, cr, cb, alpha;
    int r, g, b, r_add, g_add, b_add;
    av_dlog(avctx, "DVB clut packet:\n");
    for (i=0; i < buf_size; i++) {
        av_dlog(avctx, "%02x ", buf[i]);
        if (i % 16 == 15)
            av_dlog(avctx, "\n");
    }
    if (i % 16)
        av_dlog(avctx, "\n");
    clut_id = *buf++;
    buf += 1;
    clut = get_clut(ctx, clut_id);
    if (!clut) {
        clut = av_malloc(sizeof(DVBSubCLUT));
        memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
        clut->id = clut_id;
        clut->next = ctx->clut_list;
        ctx->clut_list = clut;
    }
    while (buf + 4 < buf_end) {
        entry_id = *buf++;
        depth = (*buf) & 0xe0;
        if (depth == 0) {
            av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
            return;
        }
        full_range = (*buf++) & 1;
        if (full_range) {
            y = *buf++;
            cr = *buf++;
            cb = *buf++;
            alpha = *buf++;
        } else {
            y = buf[0] & 0xfc;
            cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
            cb = (buf[1] << 2) & 0xf0;
            alpha = (buf[1] << 6) & 0xc0;
            buf += 2;
        }
        if (y == 0)
            alpha = 0xff;
        YUV_TO_RGB1_CCIR(cb, cr);
        YUV_TO_RGB2_CCIR(r, g, b, y);
        av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
        if (depth & 0x80)
            clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
        if (depth & 0x40)
            clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
        if (depth & 0x20)
            clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
    }
}
['static void dvbsub_parse_clut_segment(AVCodecContext *avctx,\n                                        const uint8_t *buf, int buf_size)\n{\n    DVBSubContext *ctx = avctx->priv_data;\n    const uint8_t *buf_end = buf + buf_size;\n    int i, clut_id;\n    DVBSubCLUT *clut;\n    int entry_id, depth , full_range;\n    int y, cr, cb, alpha;\n    int r, g, b, r_add, g_add, b_add;\n    av_dlog(avctx, "DVB clut packet:\\n");\n    for (i=0; i < buf_size; i++) {\n        av_dlog(avctx, "%02x ", buf[i]);\n        if (i % 16 == 15)\n            av_dlog(avctx, "\\n");\n    }\n    if (i % 16)\n        av_dlog(avctx, "\\n");\n    clut_id = *buf++;\n    buf += 1;\n    clut = get_clut(ctx, clut_id);\n    if (!clut) {\n        clut = av_malloc(sizeof(DVBSubCLUT));\n        memcpy(clut, &default_clut, sizeof(DVBSubCLUT));\n        clut->id = clut_id;\n        clut->next = ctx->clut_list;\n        ctx->clut_list = clut;\n    }\n    while (buf + 4 < buf_end) {\n        entry_id = *buf++;\n        depth = (*buf) & 0xe0;\n        if (depth == 0) {\n            av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\\n", *buf);\n            return;\n        }\n        full_range = (*buf++) & 1;\n        if (full_range) {\n            y = *buf++;\n            cr = *buf++;\n            cb = *buf++;\n            alpha = *buf++;\n        } else {\n            y = buf[0] & 0xfc;\n            cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;\n            cb = (buf[1] << 2) & 0xf0;\n            alpha = (buf[1] << 6) & 0xc0;\n            buf += 2;\n        }\n        if (y == 0)\n            alpha = 0xff;\n        YUV_TO_RGB1_CCIR(cb, cr);\n        YUV_TO_RGB2_CCIR(r, g, b, y);\n        av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\\n", entry_id, r, g, b, alpha);\n        if (depth & 0x80)\n            clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);\n        if (depth & 0x40)\n            clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);\n        if (depth & 0x20)\n            clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);\n    }\n}', 'static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)\n{\n    DVBSubCLUT *ptr = ctx->clut_list;\n    while (ptr && ptr->id != clut_id) {\n        ptr = ptr->next;\n    }\n    return ptr;\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) || !size)\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_ALIGNED_MALLOC\n    ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n    ptr = memalign(32, size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}']