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

libavcodec/dvbsubdec.c:894:1: start of procedure dvbsub_parse_clut_segment()
892. }
893. 
894. static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
     ^
895.                                         const uint8_t *buf, int buf_size)
896. {

libavcodec/dvbsubdec.c:897:5: 
895.                                         const uint8_t *buf, int buf_size)
896. {
897.     DVBSubContext *ctx = avctx->priv_data;
         ^
898. 
899.     const uint8_t *buf_end = buf + buf_size;

libavcodec/dvbsubdec.c:899:5: 
897.     DVBSubContext *ctx = avctx->priv_data;
898. 
899.     const uint8_t *buf_end = buf + buf_size;
         ^
900.     int i, clut_id;
901.     DVBSubCLUT *clut;

libavcodec/dvbsubdec.c:908:10: 
906.     av_dlog(avctx, "DVB clut packet:\n");
907. 
908.     for (i=0; i < buf_size; i++) {
              ^
909.         av_dlog(avctx, "%02x ", buf[i]);
910.         if (i % 16 == 15)

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

libavcodec/dvbsubdec.c:914:9: Taking false branch
912.     }
913. 
914.     if (i % 16)
             ^
915.         av_dlog(avctx, "\n");
916. 

libavcodec/dvbsubdec.c:917:5: 
915.         av_dlog(avctx, "\n");
916. 
917.     clut_id = *buf++;
         ^
918.     buf += 1;
919. 

libavcodec/dvbsubdec.c:918:5: 
916. 
917.     clut_id = *buf++;
918.     buf += 1;
         ^
919. 
920.     clut = get_clut(ctx, clut_id);

libavcodec/dvbsubdec.c:920:5: 
918.     buf += 1;
919. 
920.     clut = get_clut(ctx, clut_id);
         ^
921. 
922.     if (!clut) {

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

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

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

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

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

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

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

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

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

libavcodec/dvbsubdec.c:259:5: 
  257.     }
  258. 
  259.     return ptr;
           ^
  260. }
  261. 

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

libavcodec/dvbsubdec.c:922:10: Taking true branch
920.     clut = get_clut(ctx, clut_id);
921. 
922.     if (!clut) {
              ^
923.         clut = av_malloc(sizeof(DVBSubCLUT));
924. 

libavcodec/dvbsubdec.c:923:9: 
921. 
922.     if (!clut) {
923.         clut = av_malloc(sizeof(DVBSubCLUT));
             ^
924. 
925.         memcpy(clut, &default_clut, sizeof(DVBSubCLUT));

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

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

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

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

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

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

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)

libavcodec/dvbsubdec.c:925:9: 
923.         clut = av_malloc(sizeof(DVBSubCLUT));
924. 
925.         memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
             ^
926. 
927.         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}']