libavcodec/magicyuv.c:369: error: Uninitialized Value
  The value read from first_offset was never initialized.

libavcodec/magicyuv.c:369:5: 
367.     bytestream2_skip(&gbyte, s->nb_slices * s->planes);
368. 
369.     table_size = header_size + first_offset - bytestream2_tell(&gbyte);
         ^
370.     if (table_size < 2)
371.         return AVERROR_INVALIDDATA;

static int magy_decode_frame(AVCodecContext *avctx, void *data,
                             int *got_frame, AVPacket *avpkt)
{
    MagicYUVContext *s = avctx->priv_data;
    ThreadFrame frame = { .f = data };
    AVFrame *p = data;
    GetByteContext gbyte;
    GetBitContext gbit;
    uint32_t first_offset, offset, next_offset, header_size, slice_width;
    int width, height, format, version, table_size;
    int ret, i, j, k;
    bytestream2_init(&gbyte, avpkt->data, avpkt->size);
    if (bytestream2_get_le32(&gbyte) != MKTAG('M', 'A', 'G', 'Y'))
        return AVERROR_INVALIDDATA;
    header_size = bytestream2_get_le32(&gbyte);
    if (header_size < 32 || header_size >= avpkt->size) {
        av_log(avctx, AV_LOG_ERROR,
               "header or packet too small %"PRIu32"\n", header_size);
        return AVERROR_INVALIDDATA;
    }
    version = bytestream2_get_byte(&gbyte);
    if (version != 7) {
        avpriv_request_sample(avctx, "Version %d", version);
        return AVERROR_PATCHWELCOME;
    }
    s->hshift[1] =
    s->vshift[1] =
    s->hshift[2] =
    s->vshift[2] = 0;
    s->decorrelate = 0;
    format = bytestream2_get_byte(&gbyte);
    switch (format) {
    case 0x65:
        avctx->pix_fmt = AV_PIX_FMT_GBRP;
        s->decorrelate = 1;
        break;
    case 0x66:
        avctx->pix_fmt = AV_PIX_FMT_GBRAP;
        s->decorrelate = 1;
        break;
    case 0x67:
        avctx->pix_fmt = AV_PIX_FMT_YUV444P;
        break;
    case 0x68:
        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
        s->hshift[1] =
        s->hshift[2] = 1;
        break;
    case 0x69:
        avctx->pix_fmt = AV_PIX_FMT_YUV420P;
        s->hshift[1] =
        s->vshift[1] =
        s->hshift[2] =
        s->vshift[2] = 1;
        break;
    case 0x6a:
        avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
        break;
    case 0x6b:
        avctx->pix_fmt = AV_PIX_FMT_GRAY8;
        break;
    default:
        avpriv_request_sample(avctx, "Format 0x%X", format);
        return AVERROR_PATCHWELCOME;
    }
    s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);
    bytestream2_skip(&gbyte, 2);
    s->interlaced = !!(bytestream2_get_byte(&gbyte) & 2);
    bytestream2_skip(&gbyte, 3);
    width  = bytestream2_get_le32(&gbyte);
    height = bytestream2_get_le32(&gbyte);
    ret = ff_set_dimensions(avctx, width, height);
    if (ret < 0)
        return ret;
    slice_width = bytestream2_get_le32(&gbyte);
    if (slice_width != width) {
        avpriv_request_sample(avctx, "Slice width %"PRIu32, slice_width);
        return AVERROR_PATCHWELCOME;
    }
    s->slice_height = bytestream2_get_le32(&gbyte);
    if (s->slice_height <= 0 || s->slice_height > INT_MAX - height) {
        av_log(avctx, AV_LOG_ERROR,
               "invalid slice height: %d\n", s->slice_height);
        return AVERROR_INVALIDDATA;
    }
    bytestream2_skip(&gbyte, 4);
    s->nb_slices = (height + s->slice_height - 1) / s->slice_height;
    if (s->nb_slices > INT_MAX / sizeof(Slice)) {
        av_log(avctx, AV_LOG_ERROR,
               "invalid number of slices: %d\n", s->nb_slices);
        return AVERROR_INVALIDDATA;
    }
    for (i = 0; i < s->planes; i++) {
        av_fast_malloc(&s->slices[i], &s->slices_size[i], s->nb_slices * sizeof(Slice));
        if (!s->slices[i])
            return AVERROR(ENOMEM);
        offset = bytestream2_get_le32(&gbyte);
        if (offset >= avpkt->size - header_size)
            return AVERROR_INVALIDDATA;
        if (i == 0)
            first_offset = offset;
        for (j = 0; j < s->nb_slices - 1; j++) {
            s->slices[i][j].start = offset + header_size;
            next_offset = bytestream2_get_le32(&gbyte);
            if (next_offset <= offset || next_offset >= avpkt->size - header_size)
                return AVERROR_INVALIDDATA;
            s->slices[i][j].size = next_offset - offset;
            offset = next_offset;
        }
        s->slices[i][j].start = offset + header_size;
        s->slices[i][j].size  = avpkt->size - s->slices[i][j].start;
    }
    if (bytestream2_get_byte(&gbyte) != s->planes)
        return AVERROR_INVALIDDATA;
    bytestream2_skip(&gbyte, s->nb_slices * s->planes);
    table_size = header_size + first_offset - bytestream2_tell(&gbyte);
    if (table_size < 2)
        return AVERROR_INVALIDDATA;
    ret = init_get_bits8(&gbit, avpkt->data + bytestream2_tell(&gbyte), table_size);
    if (ret < 0)
        return ret;
    memset(s->len, 0, sizeof(s->len));
    j = i = 0;
    while (get_bits_left(&gbit) >= 8) {
        int b = get_bits(&gbit, 4);
        int x = get_bits(&gbit, 4);
        int l = get_bitsz(&gbit, b) + 1;
        for (k = 0; k < l; k++)
            if (j + k < 256)
                s->len[i][j + k] = x;
        j += l;
        if (j == 256) {
            j = 0;
            if (huff_build(&s->vlc[i], s->len[i])) {
                av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
                return AVERROR_INVALIDDATA;
            }
            i++;
            if (i == s->planes) {
                break;
            }
        } else if (j > 256) {
            return AVERROR_INVALIDDATA;
        }
    }
    if (i != s->planes) {
        av_log(avctx, AV_LOG_ERROR, "Huffman tables too short\n");
        return AVERROR_INVALIDDATA;
    }
    p->pict_type = AV_PICTURE_TYPE_I;
    p->key_frame = 1;
    if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
        return ret;
    s->buf = avpkt->data;
    s->p = p;
    avctx->execute2(avctx, magy_decode_slice, NULL, NULL, s->nb_slices);
    if (avctx->pix_fmt == AV_PIX_FMT_GBRP ||
        avctx->pix_fmt == AV_PIX_FMT_GBRAP) {
        FFSWAP(uint8_t*, p->data[0], p->data[1]);
        FFSWAP(int, p->linesize[0], p->linesize[1]);
    }
    *got_frame = 1;
    return avpkt->size;
}
['static int magy_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame, AVPacket *avpkt)\n{\n    MagicYUVContext *s = avctx->priv_data;\n    ThreadFrame frame = { .f = data };\n    AVFrame *p = data;\n    GetByteContext gbyte;\n    GetBitContext gbit;\n    uint32_t first_offset, offset, next_offset, header_size, slice_width;\n    int width, height, format, version, table_size;\n    int ret, i, j, k;\n    bytestream2_init(&gbyte, avpkt->data, avpkt->size);\n    if (bytestream2_get_le32(&gbyte) != MKTAG(\'M\', \'A\', \'G\', \'Y\'))\n        return AVERROR_INVALIDDATA;\n    header_size = bytestream2_get_le32(&gbyte);\n    if (header_size < 32 || header_size >= avpkt->size) {\n        av_log(avctx, AV_LOG_ERROR,\n               "header or packet too small %"PRIu32"\\n", header_size);\n        return AVERROR_INVALIDDATA;\n    }\n    version = bytestream2_get_byte(&gbyte);\n    if (version != 7) {\n        avpriv_request_sample(avctx, "Version %d", version);\n        return AVERROR_PATCHWELCOME;\n    }\n    s->hshift[1] =\n    s->vshift[1] =\n    s->hshift[2] =\n    s->vshift[2] = 0;\n    s->decorrelate = 0;\n    format = bytestream2_get_byte(&gbyte);\n    switch (format) {\n    case 0x65:\n        avctx->pix_fmt = AV_PIX_FMT_GBRP;\n        s->decorrelate = 1;\n        break;\n    case 0x66:\n        avctx->pix_fmt = AV_PIX_FMT_GBRAP;\n        s->decorrelate = 1;\n        break;\n    case 0x67:\n        avctx->pix_fmt = AV_PIX_FMT_YUV444P;\n        break;\n    case 0x68:\n        avctx->pix_fmt = AV_PIX_FMT_YUV422P;\n        s->hshift[1] =\n        s->hshift[2] = 1;\n        break;\n    case 0x69:\n        avctx->pix_fmt = AV_PIX_FMT_YUV420P;\n        s->hshift[1] =\n        s->vshift[1] =\n        s->hshift[2] =\n        s->vshift[2] = 1;\n        break;\n    case 0x6a:\n        avctx->pix_fmt = AV_PIX_FMT_YUVA444P;\n        break;\n    case 0x6b:\n        avctx->pix_fmt = AV_PIX_FMT_GRAY8;\n        break;\n    default:\n        avpriv_request_sample(avctx, "Format 0x%X", format);\n        return AVERROR_PATCHWELCOME;\n    }\n    s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);\n    bytestream2_skip(&gbyte, 2);\n    s->interlaced = !!(bytestream2_get_byte(&gbyte) & 2);\n    bytestream2_skip(&gbyte, 3);\n    width  = bytestream2_get_le32(&gbyte);\n    height = bytestream2_get_le32(&gbyte);\n    ret = ff_set_dimensions(avctx, width, height);\n    if (ret < 0)\n        return ret;\n    slice_width = bytestream2_get_le32(&gbyte);\n    if (slice_width != width) {\n        avpriv_request_sample(avctx, "Slice width %"PRIu32, slice_width);\n        return AVERROR_PATCHWELCOME;\n    }\n    s->slice_height = bytestream2_get_le32(&gbyte);\n    if (s->slice_height <= 0 || s->slice_height > INT_MAX - height) {\n        av_log(avctx, AV_LOG_ERROR,\n               "invalid slice height: %d\\n", s->slice_height);\n        return AVERROR_INVALIDDATA;\n    }\n    bytestream2_skip(&gbyte, 4);\n    s->nb_slices = (height + s->slice_height - 1) / s->slice_height;\n    if (s->nb_slices > INT_MAX / sizeof(Slice)) {\n        av_log(avctx, AV_LOG_ERROR,\n               "invalid number of slices: %d\\n", s->nb_slices);\n        return AVERROR_INVALIDDATA;\n    }\n    for (i = 0; i < s->planes; i++) {\n        av_fast_malloc(&s->slices[i], &s->slices_size[i], s->nb_slices * sizeof(Slice));\n        if (!s->slices[i])\n            return AVERROR(ENOMEM);\n        offset = bytestream2_get_le32(&gbyte);\n        if (offset >= avpkt->size - header_size)\n            return AVERROR_INVALIDDATA;\n        if (i == 0)\n            first_offset = offset;\n        for (j = 0; j < s->nb_slices - 1; j++) {\n            s->slices[i][j].start = offset + header_size;\n            next_offset = bytestream2_get_le32(&gbyte);\n            if (next_offset <= offset || next_offset >= avpkt->size - header_size)\n                return AVERROR_INVALIDDATA;\n            s->slices[i][j].size = next_offset - offset;\n            offset = next_offset;\n        }\n        s->slices[i][j].start = offset + header_size;\n        s->slices[i][j].size  = avpkt->size - s->slices[i][j].start;\n    }\n    if (bytestream2_get_byte(&gbyte) != s->planes)\n        return AVERROR_INVALIDDATA;\n    bytestream2_skip(&gbyte, s->nb_slices * s->planes);\n    table_size = header_size + first_offset - bytestream2_tell(&gbyte);\n    if (table_size < 2)\n        return AVERROR_INVALIDDATA;\n    ret = init_get_bits8(&gbit, avpkt->data + bytestream2_tell(&gbyte), table_size);\n    if (ret < 0)\n        return ret;\n    memset(s->len, 0, sizeof(s->len));\n    j = i = 0;\n    while (get_bits_left(&gbit) >= 8) {\n        int b = get_bits(&gbit, 4);\n        int x = get_bits(&gbit, 4);\n        int l = get_bitsz(&gbit, b) + 1;\n        for (k = 0; k < l; k++)\n            if (j + k < 256)\n                s->len[i][j + k] = x;\n        j += l;\n        if (j == 256) {\n            j = 0;\n            if (huff_build(&s->vlc[i], s->len[i])) {\n                av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\\n");\n                return AVERROR_INVALIDDATA;\n            }\n            i++;\n            if (i == s->planes) {\n                break;\n            }\n        } else if (j > 256) {\n            return AVERROR_INVALIDDATA;\n        }\n    }\n    if (i != s->planes) {\n        av_log(avctx, AV_LOG_ERROR, "Huffman tables too short\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    p->pict_type = AV_PICTURE_TYPE_I;\n    p->key_frame = 1;\n    if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)\n        return ret;\n    s->buf = avpkt->data;\n    s->p = p;\n    avctx->execute2(avctx, magy_decode_slice, NULL, NULL, s->nb_slices);\n    if (avctx->pix_fmt == AV_PIX_FMT_GBRP ||\n        avctx->pix_fmt == AV_PIX_FMT_GBRAP) {\n        FFSWAP(uint8_t*, p->data[0], p->data[1]);\n        FFSWAP(int, p->linesize[0], p->linesize[1]);\n    }\n    *got_frame = 1;\n    return avpkt->size;\n}']