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

libavcodec/dvbsubdec.c:1312:1: start of procedure dvbsub_display_end_segment()
1310. }
1311. 
1312. static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
      ^
1313.                                         int buf_size, AVSubtitle *sub)
1314. {

libavcodec/dvbsubdec.c:1315:5: 
1313.                                         int buf_size, AVSubtitle *sub)
1314. {
1315.     DVBSubContext *ctx = avctx->priv_data;
          ^
1316.     DVBSubDisplayDefinition *display_def = ctx->display_definition;
1317. 

libavcodec/dvbsubdec.c:1316:5: 
1314. {
1315.     DVBSubContext *ctx = avctx->priv_data;
1316.     DVBSubDisplayDefinition *display_def = ctx->display_definition;
          ^
1317. 
1318.     DVBSubRegion *region;

libavcodec/dvbsubdec.c:1324:5: 
1322.     uint32_t *clut_table;
1323.     int i;
1324.     int offset_x=0, offset_y=0;
          ^
1325. 
1326.     sub->rects = NULL;

libavcodec/dvbsubdec.c:1326:5: 
1324.     int offset_x=0, offset_y=0;
1325. 
1326.     sub->rects = NULL;
          ^
1327.     sub->start_display_time = 0;
1328.     sub->end_display_time = ctx->time_out * 1000;

libavcodec/dvbsubdec.c:1327:5: 
1325. 
1326.     sub->rects = NULL;
1327.     sub->start_display_time = 0;
          ^
1328.     sub->end_display_time = ctx->time_out * 1000;
1329.     sub->format = 0;

libavcodec/dvbsubdec.c:1328:5: 
1326.     sub->rects = NULL;
1327.     sub->start_display_time = 0;
1328.     sub->end_display_time = ctx->time_out * 1000;
          ^
1329.     sub->format = 0;
1330. 

libavcodec/dvbsubdec.c:1329:5: 
1327.     sub->start_display_time = 0;
1328.     sub->end_display_time = ctx->time_out * 1000;
1329.     sub->format = 0;
          ^
1330. 
1331.     if (display_def) {

libavcodec/dvbsubdec.c:1331:9: Taking true branch
1329.     sub->format = 0;
1330. 
1331.     if (display_def) {
              ^
1332.         offset_x = display_def->x;
1333.         offset_y = display_def->y;

libavcodec/dvbsubdec.c:1332:9: 
1330. 
1331.     if (display_def) {
1332.         offset_x = display_def->x;
              ^
1333.         offset_y = display_def->y;
1334.     }

libavcodec/dvbsubdec.c:1333:9: 
1331.     if (display_def) {
1332.         offset_x = display_def->x;
1333.         offset_y = display_def->y;
              ^
1334.     }
1335. 

libavcodec/dvbsubdec.c:1336:5: 
1334.     }
1335. 
1336.     sub->num_rects = ctx->display_list_size;
          ^
1337. 
1338.     if (sub->num_rects > 0){

libavcodec/dvbsubdec.c:1338:9: Taking false branch
1336.     sub->num_rects = ctx->display_list_size;
1337. 
1338.     if (sub->num_rects > 0){
              ^
1339.         sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);
1340.         for(i=0; i<sub->num_rects; i++)

libavcodec/dvbsubdec.c:1344:5: 
1342.     }
1343. 
1344.     i = 0;
          ^
1345. 
1346.     for (display = ctx->display_list; display; display = display->next) {

libavcodec/dvbsubdec.c:1346:10: 
1344.     i = 0;
1345. 
1346.     for (display = ctx->display_list; display; display = display->next) {
               ^
1347.         region = get_region(ctx, display->region_id);
1348.         rect = sub->rects[i];

libavcodec/dvbsubdec.c:1346:39: Loop condition is true. Entering loop body
1344.     i = 0;
1345. 
1346.     for (display = ctx->display_list; display; display = display->next) {
                                            ^
1347.         region = get_region(ctx, display->region_id);
1348.         rect = sub->rects[i];

libavcodec/dvbsubdec.c:1347:9: 
1345. 
1346.     for (display = ctx->display_list; display; display = display->next) {
1347.         region = get_region(ctx, display->region_id);
              ^
1348.         rect = sub->rects[i];
1349. 

libavcodec/dvbsubdec.c:267:1: start of procedure get_region()
  265. }
  266. 
  267. static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
       ^
  268. {
  269.     DVBSubRegion *ptr = ctx->region_list;

libavcodec/dvbsubdec.c:269:5: 
  267. static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
  268. {
  269.     DVBSubRegion *ptr = ctx->region_list;
           ^
  270. 
  271.     while (ptr && ptr->id != region_id) {

libavcodec/dvbsubdec.c:271:12: Loop condition is true. Entering loop body
  269.     DVBSubRegion *ptr = ctx->region_list;
  270. 
  271.     while (ptr && ptr->id != region_id) {
                  ^
  272.         ptr = ptr->next;
  273.     }

libavcodec/dvbsubdec.c:271:19: Loop condition is true. Entering loop body
  269.     DVBSubRegion *ptr = ctx->region_list;
  270. 
  271.     while (ptr && ptr->id != region_id) {
                         ^
  272.         ptr = ptr->next;
  273.     }

libavcodec/dvbsubdec.c:272:9: 
  270. 
  271.     while (ptr && ptr->id != region_id) {
  272.         ptr = ptr->next;
               ^
  273.     }
  274. 

libavcodec/dvbsubdec.c:271:12: Loop condition is true. Entering loop body
  269.     DVBSubRegion *ptr = ctx->region_list;
  270. 
  271.     while (ptr && ptr->id != region_id) {
                  ^
  272.         ptr = ptr->next;
  273.     }

libavcodec/dvbsubdec.c:271:19: Loop condition is true. Entering loop body
  269.     DVBSubRegion *ptr = ctx->region_list;
  270. 
  271.     while (ptr && ptr->id != region_id) {
                         ^
  272.         ptr = ptr->next;
  273.     }

libavcodec/dvbsubdec.c:272:9: 
  270. 
  271.     while (ptr && ptr->id != region_id) {
  272.         ptr = ptr->next;
               ^
  273.     }
  274. 

libavcodec/dvbsubdec.c:271:12: Loop condition is true. Entering loop body
  269.     DVBSubRegion *ptr = ctx->region_list;
  270. 
  271.     while (ptr && ptr->id != region_id) {
                  ^
  272.         ptr = ptr->next;
  273.     }

libavcodec/dvbsubdec.c:271:19: Loop condition is false. Leaving loop
  269.     DVBSubRegion *ptr = ctx->region_list;
  270. 
  271.     while (ptr && ptr->id != region_id) {
                         ^
  272.         ptr = ptr->next;
  273.     }

libavcodec/dvbsubdec.c:275:5: 
  273.     }
  274. 
  275.     return ptr;
           ^
  276. }
  277. 

libavcodec/dvbsubdec.c:276:1: return from a call to get_region
  274. 
  275.     return ptr;
  276. }
       ^
  277. 
  278. static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)

libavcodec/dvbsubdec.c:1348:9: 
1346.     for (display = ctx->display_list; display; display = display->next) {
1347.         region = get_region(ctx, display->region_id);
1348.         rect = sub->rects[i];
              ^
1349. 
1350.         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);
        for(i=0; i<sub->num_rects; i++)
            sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
    }
    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->pict.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->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
        memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
        rect->pict.data[0] = av_malloc(region->buf_size);
        memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
        i++;
    }
    sub->num_rects = i;
#ifdef DEBUG_SAVE_IMAGES
    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        for(i=0; i<sub->num_rects; i++)\n            sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));\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->pict.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->pict.data[1] = av_mallocz(AVPALETTE_SIZE);\n        memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));\n        rect->pict.data[0] = av_malloc(region->buf_size);\n        memcpy(rect->pict.data[0], region->pbuf, region->buf_size);\n        i++;\n    }\n    sub->num_rects = i;\n#ifdef DEBUG_SAVE_IMAGES\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}']