libavcodec/dvbsubdec.c:1309: error: Null Dereference
  pointer `sub->rects` last assigned on line 1277 could be null and is dereferenced at line 1309, column 16.

libavcodec/dvbsubdec.c:1263:1: start of procedure dvbsub_display_end_segment()
1261. }
1262. 
1263. static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
      ^
1264.                                       int buf_size, AVSubtitle *sub)
1265. {

libavcodec/dvbsubdec.c:1266:5: 
1264.                                       int buf_size, AVSubtitle *sub)
1265. {
1266.     DVBSubContext *ctx = avctx->priv_data;
          ^
1267.     DVBSubDisplayDefinition *display_def = ctx->display_definition;
1268. 

libavcodec/dvbsubdec.c:1267:5: 
1265. {
1266.     DVBSubContext *ctx = avctx->priv_data;
1267.     DVBSubDisplayDefinition *display_def = ctx->display_definition;
          ^
1268. 
1269.     DVBSubRegion *region;

libavcodec/dvbsubdec.c:1275:5: 
1273.     uint32_t *clut_table;
1274.     int i;
1275.     int offset_x=0, offset_y=0;
          ^
1276. 
1277.     sub->rects = NULL;

libavcodec/dvbsubdec.c:1277:5: 
1275.     int offset_x=0, offset_y=0;
1276. 
1277.     sub->rects = NULL;
          ^
1278.     sub->start_display_time = 0;
1279.     sub->end_display_time = ctx->time_out * 1000;

libavcodec/dvbsubdec.c:1278:5: 
1276. 
1277.     sub->rects = NULL;
1278.     sub->start_display_time = 0;
          ^
1279.     sub->end_display_time = ctx->time_out * 1000;
1280.     sub->format = 0;

libavcodec/dvbsubdec.c:1279:5: 
1277.     sub->rects = NULL;
1278.     sub->start_display_time = 0;
1279.     sub->end_display_time = ctx->time_out * 1000;
          ^
1280.     sub->format = 0;
1281. 

libavcodec/dvbsubdec.c:1280:5: 
1278.     sub->start_display_time = 0;
1279.     sub->end_display_time = ctx->time_out * 1000;
1280.     sub->format = 0;
          ^
1281. 
1282.     if (display_def) {

libavcodec/dvbsubdec.c:1282:9: Taking true branch
1280.     sub->format = 0;
1281. 
1282.     if (display_def) {
              ^
1283.         offset_x = display_def->x;
1284.         offset_y = display_def->y;

libavcodec/dvbsubdec.c:1283:9: 
1281. 
1282.     if (display_def) {
1283.         offset_x = display_def->x;
              ^
1284.         offset_y = display_def->y;
1285.     }

libavcodec/dvbsubdec.c:1284:9: 
1282.     if (display_def) {
1283.         offset_x = display_def->x;
1284.         offset_y = display_def->y;
              ^
1285.     }
1286. 

libavcodec/dvbsubdec.c:1287:5: 
1285.     }
1286. 
1287.     sub->num_rects = ctx->display_list_size;
          ^
1288. 
1289.     if (sub->num_rects > 0) {

libavcodec/dvbsubdec.c:1289:9: Taking false branch
1287.     sub->num_rects = ctx->display_list_size;
1288. 
1289.     if (sub->num_rects > 0) {
              ^
1290.         sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);
1291.         if (!sub->rects)

libavcodec/dvbsubdec.c:1305:5: 
1303.     }
1304. 
1305.     i = 0;
          ^
1306. 
1307.     for (display = ctx->display_list; display; display = display->next) {

libavcodec/dvbsubdec.c:1307:10: 
1305.     i = 0;
1306. 
1307.     for (display = ctx->display_list; display; display = display->next) {
               ^
1308.         region = get_region(ctx, display->region_id);
1309.         rect = sub->rects[i];

libavcodec/dvbsubdec.c:1307:39: Loop condition is true. Entering loop body
1305.     i = 0;
1306. 
1307.     for (display = ctx->display_list; display; display = display->next) {
                                            ^
1308.         region = get_region(ctx, display->region_id);
1309.         rect = sub->rects[i];

libavcodec/dvbsubdec.c:1308:9: 
1306. 
1307.     for (display = ctx->display_list; display; display = display->next) {
1308.         region = get_region(ctx, display->region_id);
              ^
1309.         rect = sub->rects[i];
1310. 

libavcodec/dvbsubdec.c:148:1: start of procedure get_region()
  146. }
  147. 
  148. static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
       ^
  149. {
  150.     DVBSubRegion *ptr = ctx->region_list;

libavcodec/dvbsubdec.c:150:5: 
  148. static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
  149. {
  150.     DVBSubRegion *ptr = ctx->region_list;
           ^
  151. 
  152.     while (ptr && ptr->id != region_id) {

libavcodec/dvbsubdec.c:152:12: Loop condition is true. Entering loop body
  150.     DVBSubRegion *ptr = ctx->region_list;
  151. 
  152.     while (ptr && ptr->id != region_id) {
                  ^
  153.         ptr = ptr->next;
  154.     }

libavcodec/dvbsubdec.c:152:19: Loop condition is true. Entering loop body
  150.     DVBSubRegion *ptr = ctx->region_list;
  151. 
  152.     while (ptr && ptr->id != region_id) {
                         ^
  153.         ptr = ptr->next;
  154.     }

libavcodec/dvbsubdec.c:153:9: 
  151. 
  152.     while (ptr && ptr->id != region_id) {
  153.         ptr = ptr->next;
               ^
  154.     }
  155. 

libavcodec/dvbsubdec.c:152:12: Loop condition is true. Entering loop body
  150.     DVBSubRegion *ptr = ctx->region_list;
  151. 
  152.     while (ptr && ptr->id != region_id) {
                  ^
  153.         ptr = ptr->next;
  154.     }

libavcodec/dvbsubdec.c:152:19: Loop condition is true. Entering loop body
  150.     DVBSubRegion *ptr = ctx->region_list;
  151. 
  152.     while (ptr && ptr->id != region_id) {
                         ^
  153.         ptr = ptr->next;
  154.     }

libavcodec/dvbsubdec.c:153:9: 
  151. 
  152.     while (ptr && ptr->id != region_id) {
  153.         ptr = ptr->next;
               ^
  154.     }
  155. 

libavcodec/dvbsubdec.c:152:12: Loop condition is true. Entering loop body
  150.     DVBSubRegion *ptr = ctx->region_list;
  151. 
  152.     while (ptr && ptr->id != region_id) {
                  ^
  153.         ptr = ptr->next;
  154.     }

libavcodec/dvbsubdec.c:152:19: Loop condition is false. Leaving loop
  150.     DVBSubRegion *ptr = ctx->region_list;
  151. 
  152.     while (ptr && ptr->id != region_id) {
                         ^
  153.         ptr = ptr->next;
  154.     }

libavcodec/dvbsubdec.c:156:5: 
  154.     }
  155. 
  156.     return ptr;
           ^
  157. }
  158. 

libavcodec/dvbsubdec.c:157:1: return from a call to get_region
  155. 
  156.     return ptr;
  157. }
       ^
  158. 
  159. static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)

libavcodec/dvbsubdec.c:1309:9: 
1307.     for (display = ctx->display_list; display; display = display->next) {
1308.         region = get_region(ctx, display->region_id);
1309.         rect = sub->rects[i];
              ^
1310. 
1311.         if (!region)

static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
                                      int buf_size, AVSubtitle *sub)
{
    DVBSubContext *ctx = avctx->priv_data;
    DVBSubDisplayDefinition *display_def = ctx->display_definition;
    DVBSubRegion *region;
    DVBSubRegionDisplay *display;
    AVSubtitleRect *rect;
    DVBSubCLUT *clut;
    uint32_t *clut_table;
    int i;
    int offset_x=0, offset_y=0;
    sub->rects = NULL;
    sub->start_display_time = 0;
    sub->end_display_time = ctx->time_out * 1000;
    sub->format = 0;
    if (display_def) {
        offset_x = display_def->x;
        offset_y = display_def->y;
    }
    sub->num_rects = ctx->display_list_size;
    if (sub->num_rects > 0) {
        sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);
        if (!sub->rects)
            return AVERROR(ENOMEM);
        for (i = 0; i < sub->num_rects; i++) {
            sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
            if (!sub->rects[i]) {
                int j;
                for (j = 0; j < i; j ++)
                    av_free(sub->rects[j]);
                av_free(sub->rects);
                return AVERROR(ENOMEM);
            }
        }
    }
    i = 0;
    for (display = ctx->display_list; display; display = display->next) {
        region = get_region(ctx, display->region_id);
        rect = sub->rects[i];
        if (!region)
            continue;
        rect->x = display->x_pos + offset_x;
        rect->y = display->y_pos + offset_y;
        rect->w = region->width;
        rect->h = region->height;
        rect->nb_colors = 16;
        rect->type      = SUBTITLE_BITMAP;
        rect->linesize[0] = region->width;
        clut = get_clut(ctx, region->clut);
        if (!clut)
            clut = &default_clut;
        switch (region->depth) {
        case 2:
            clut_table = clut->clut4;
            break;
        case 8:
            clut_table = clut->clut256;
            break;
        case 4:
        default:
            clut_table = clut->clut16;
            break;
        }
        rect->data[1] = av_mallocz(AVPALETTE_SIZE);
        if (!rect->data[1]) {
            for (i = 0; i < sub->num_rects; i++)
                av_free(sub->rects[i]);
            av_free(sub->rects);
            return AVERROR(ENOMEM);
        }
        memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
        rect->data[0] = av_malloc(region->buf_size);
        if (!rect->data[0]) {
            av_free(rect->data[1]);
            for (i = 0; i < sub->num_rects; i++)
                av_free(sub->rects[i]);
            av_free(sub->rects);
            return AVERROR(ENOMEM);
        }
        memcpy(rect->data[0], region->pbuf, region->buf_size);
#if FF_API_AVPICTURE
FF_DISABLE_DEPRECATION_WARNINGS
{
        int j;
        for (j = 0; j < 4; j++) {
            rect->pict.data[j] = rect->data[j];
            rect->pict.linesize[j] = rect->linesize[j];
        }
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif
        i++;
    }
    sub->num_rects = i;
#ifdef DEBUG
    save_display_set(ctx);
#endif
    return 1;
}
['static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,\n                                      int buf_size, AVSubtitle *sub)\n{\n    DVBSubContext *ctx = avctx->priv_data;\n    DVBSubDisplayDefinition *display_def = ctx->display_definition;\n    DVBSubRegion *region;\n    DVBSubRegionDisplay *display;\n    AVSubtitleRect *rect;\n    DVBSubCLUT *clut;\n    uint32_t *clut_table;\n    int i;\n    int offset_x=0, offset_y=0;\n    sub->rects = NULL;\n    sub->start_display_time = 0;\n    sub->end_display_time = ctx->time_out * 1000;\n    sub->format = 0;\n    if (display_def) {\n        offset_x = display_def->x;\n        offset_y = display_def->y;\n    }\n    sub->num_rects = ctx->display_list_size;\n    if (sub->num_rects > 0) {\n        sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);\n        if (!sub->rects)\n            return AVERROR(ENOMEM);\n        for (i = 0; i < sub->num_rects; i++) {\n            sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));\n            if (!sub->rects[i]) {\n                int j;\n                for (j = 0; j < i; j ++)\n                    av_free(sub->rects[j]);\n                av_free(sub->rects);\n                return AVERROR(ENOMEM);\n            }\n        }\n    }\n    i = 0;\n    for (display = ctx->display_list; display; display = display->next) {\n        region = get_region(ctx, display->region_id);\n        rect = sub->rects[i];\n        if (!region)\n            continue;\n        rect->x = display->x_pos + offset_x;\n        rect->y = display->y_pos + offset_y;\n        rect->w = region->width;\n        rect->h = region->height;\n        rect->nb_colors = 16;\n        rect->type      = SUBTITLE_BITMAP;\n        rect->linesize[0] = region->width;\n        clut = get_clut(ctx, region->clut);\n        if (!clut)\n            clut = &default_clut;\n        switch (region->depth) {\n        case 2:\n            clut_table = clut->clut4;\n            break;\n        case 8:\n            clut_table = clut->clut256;\n            break;\n        case 4:\n        default:\n            clut_table = clut->clut16;\n            break;\n        }\n        rect->data[1] = av_mallocz(AVPALETTE_SIZE);\n        if (!rect->data[1]) {\n            for (i = 0; i < sub->num_rects; i++)\n                av_free(sub->rects[i]);\n            av_free(sub->rects);\n            return AVERROR(ENOMEM);\n        }\n        memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));\n        rect->data[0] = av_malloc(region->buf_size);\n        if (!rect->data[0]) {\n            av_free(rect->data[1]);\n            for (i = 0; i < sub->num_rects; i++)\n                av_free(sub->rects[i]);\n            av_free(sub->rects);\n            return AVERROR(ENOMEM);\n        }\n        memcpy(rect->data[0], region->pbuf, region->buf_size);\n#if FF_API_AVPICTURE\nFF_DISABLE_DEPRECATION_WARNINGS\n{\n        int j;\n        for (j = 0; j < 4; j++) {\n            rect->pict.data[j] = rect->data[j];\n            rect->pict.linesize[j] = rect->linesize[j];\n        }\n}\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n        i++;\n    }\n    sub->num_rects = i;\n#ifdef DEBUG\n    save_display_set(ctx);\n#endif\n    return 1;\n}', 'static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)\n{\n    DVBSubRegion *ptr = ctx->region_list;\n    while (ptr && ptr->id != region_id) {\n        ptr = ptr->next;\n    }\n    return ptr;\n}']