libavdevice/dv1394.c:202: error: Buffer Overrun L2
  Offset: [0, 7] Size: 3 by call to `dv_produce_packet`.

libavdevice/dv1394.c:170:13: Unknown value from: ioctl
168.         }
169. 
170.         if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) {
                 ^
171.             av_log(context, AV_LOG_ERROR, "Failed to get status: %s\n", strerror(errno));
172.             return AVERROR(EIO);

libavdevice/dv1394.c:202:12: Call
200. #endif
201. 
202.     size = dv_produce_packet(dv->dv_demux, pkt,
                ^
203.                              dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE),
204.                              DV1394_PAL_FRAME_SIZE);

libavformat/dv.c:309:1: Parameter `*buf`
  307. }
  308. 
  309. int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
       ^
  310.                       uint8_t* buf, int buf_size)
  311. {

libavformat/dv.c:315:20: Call
  313. 
  314.     if (buf_size < DV_PROFILE_BYTES ||
  315.         !(c->sys = dv_frame_profile(buf)) ||
                          ^
  316.         buf_size < c->sys->frame_size) {
  317.           return -1;   /* Broken frame, or not enough data */

libavcodec/dvdata.h:2664:1: Parameter `*frame`
    2662. #define DV_MAX_FRAME_SIZE 288000
    2663. 
    2664. static inline const DVprofile* dv_frame_profile(const uint8_t* frame)
          ^
    2665. {
    2666.     if ((frame[3] & 0x80) == 0) {      /* DSF flag */

libavformat/dv.c:322:12: Call
  320.     /* Queueing audio packet */
  321.     /* FIXME: in case of no audio/bad audio we have to do something */
  322.     size = dv_extract_audio_info(c, buf);
                  ^
  323.     for (i=0; i<c->ach; i++) {
  324.        c->audio_pkt[i].size = size;

libavformat/dv.c:182:1: Parameter `*frame`
    180. }
    181. 
    182. static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
         ^
    183. {
    184.     const uint8_t* as_pack;

libavformat/dv.c:187:15: Call
    185.     int freq, stype, smpls, quant, i, ach;
    186. 
    187.     as_pack = dv_extract_pack(frame, dv_audio_source);
                       ^
    188.     if (!as_pack || !c->sys) {    /* No audio ? */
    189.         c->ach = 0;

libavformat/dv.c:72:1: Parameter `t`
      70.  * to have a fallback mechanism for complete search of missing packs.
      71.  */
      72. static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
          ^
      73. {
      74.     int offs;

libavformat/dv.c:327:5: Call
  325.        c->audio_pkt[i].pts  = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;
  326.     }
  327.     dv_extract_audio(buf, c->audio_buf[0], c->audio_buf[1], c->sys);
           ^
  328.     c->abytes += size;
  329. 

libavformat/dv.c:101:1: <Offset trace>
 99.  *    are converted into 16bit linear ones.
100.  */
101. static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
     ^
102.                             const DVprofile *sys)
103. {

libavformat/dv.c:101:1: Parameter `*frame`
     99.  *    are converted into 16bit linear ones.
    100.  */
    101. static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
         ^
    102.                             const DVprofile *sys)
    103. {

libavformat/dv.c:108:15: Call
    106.     const uint8_t* as_pack;
    107. 
    108.     as_pack = dv_extract_pack(frame, dv_audio_source);
                       ^
    109.     if (!as_pack)    /* No audio ? */
    110.         return 0;

libavformat/dv.c:72:1: Parameter `t`
      70.  * to have a fallback mechanism for complete search of missing packs.
      71.  */
      72. static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
          ^
      73. {
      74.     int offs;

libavformat/dv.c:113:5: Assignment
    111. 
    112.     smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
    113.     freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
             ^
    114.     quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
    115. 

libavformat/dv.c:101:1: <Length trace>
 99.  *    are converted into 16bit linear ones.
100.  */
101. static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
     ^
102.                             const DVprofile *sys)
103. {

libavformat/dv.c:101:1: Parameter `sys->audio_min_samples[*]`
     99.  *    are converted into 16bit linear ones.
    100.  */
    101. static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
         ^
    102.                             const DVprofile *sys)
    103. {

libavformat/dv.c:119:13: Array access: Offset: [0, 7] Size: 3 by call to `dv_produce_packet` 
    117.         return -1; /* Unsupported quantization */
    118. 
    119.     size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
                     ^
    120.     half_ch = sys->difseg_size/2;
    121. 

static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
                            const DVprofile *sys)
{
    int size, chan, i, j, d, of, smpls, freq, quant, half_ch;
    uint16_t lc, rc;
    const uint8_t* as_pack;
    as_pack = dv_extract_pack(frame, dv_audio_source);
    if (!as_pack)
        return 0;
    smpls = as_pack[1] & 0x3f;
    freq = (as_pack[4] >> 3) & 0x07;
    quant = as_pack[4] & 0x07;
    if (quant > 1)
        return -1;
    size = (sys->audio_min_samples[freq] + smpls) * 4;
    half_ch = sys->difseg_size/2;
    for (chan = 0; chan < sys->n_difchan; chan++) {
        for (i = 0; i < sys->difseg_size; i++) {
            frame += 6 * 80;
            if (quant == 1 && i == half_ch) {
                if (!pcm2)
                    break;
                else
                    pcm = pcm2;
            }
            for (j = 0; j < 9; j++) {
                for (d = 8; d < 80; d += 2) {
                    if (quant == 0) {
                        of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;
                        if (of*2 >= size)
                            continue;
                        pcm[of*2] = frame[d+1];
                        pcm[of*2+1] = frame[d];
                        if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
                            pcm[of*2+1] = 0;
                    } else {
                        lc = ((uint16_t)frame[d] << 4) |
                             ((uint16_t)frame[d+2] >> 4);
                        rc = ((uint16_t)frame[d+1] << 4) |
                             ((uint16_t)frame[d+2] & 0x0f);
                        lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
                        rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
                        of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride;
                        if (of*2 >= size)
                            continue;
                        pcm[of*2] = lc & 0xff;
                        pcm[of*2+1] = lc >> 8;
                        of = sys->audio_shuffle[i%half_ch+half_ch][j] +
                            (d - 8)/3 * sys->audio_stride;
                        pcm[of*2] = rc & 0xff;
                        pcm[of*2+1] = rc >> 8;
                        ++d;
                    }
                }
                frame += 16 * 80;
            }
        }
        if(!pcm2)
            break;
        pcm = pcm2;
    }
    return size;
}
['static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)\n{\n    struct dv1394_data *dv = context->priv_data;\n    int size;\n    size = dv_get_packet(dv->dv_demux, pkt);\n    if (size > 0)\n        return size;\n    if (!dv->avail) {\n        struct dv1394_status s;\n        struct pollfd p;\n        if (dv->done) {\n            if (ioctl(dv->fd, DV1394_RECEIVE_FRAMES, dv->done) < 0) {\n                av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\\n");\n                dv1394_reset(dv);\n                dv1394_start(dv);\n            }\n            dv->done = 0;\n        }\nrestart_poll:\n        p.fd = dv->fd;\n        p.events = POLLIN | POLLERR | POLLHUP;\n        if (poll(&p, 1, -1) < 0) {\n            if (errno == EAGAIN || errno == EINTR)\n                goto restart_poll;\n            av_log(context, AV_LOG_ERROR, "Poll failed: %s\\n", strerror(errno));\n            return AVERROR(EIO);\n        }\n        if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) {\n            av_log(context, AV_LOG_ERROR, "Failed to get status: %s\\n", strerror(errno));\n            return AVERROR(EIO);\n        }\n#ifdef DV1394_DEBUG\n        av_log(context, AV_LOG_DEBUG, "DV1394: status\\n"\n                "\\tactive_frame\\t%d\\n"\n                "\\tfirst_clear_frame\\t%d\\n"\n                "\\tn_clear_frames\\t%d\\n"\n                "\\tdropped_frames\\t%d\\n",\n                s.active_frame, s.first_clear_frame,\n                s.n_clear_frames, s.dropped_frames);\n#endif\n        dv->avail = s.n_clear_frames;\n        dv->index = s.first_clear_frame;\n        dv->done  = 0;\n        if (s.dropped_frames) {\n            av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\\n",\n                    s.dropped_frames);\n            dv1394_reset(dv);\n            dv1394_start(dv);\n        }\n    }\n#ifdef DV1394_DEBUG\n    av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\\n", dv->index, dv->avail,\n            dv->done);\n#endif\n    size = dv_produce_packet(dv->dv_demux, pkt,\n                             dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE),\n                             DV1394_PAL_FRAME_SIZE);\n    dv->index = (dv->index + 1) % DV1394_RING_FRAMES;\n    dv->done++; dv->avail--;\n    return size;\n}', 'int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,\n                      uint8_t* buf, int buf_size)\n{\n    int size, i;\n    if (buf_size < DV_PROFILE_BYTES ||\n        !(c->sys = dv_frame_profile(buf)) ||\n        buf_size < c->sys->frame_size) {\n          return -1;\n    }\n    size = dv_extract_audio_info(c, buf);\n    for (i=0; i<c->ach; i++) {\n       c->audio_pkt[i].size = size;\n       c->audio_pkt[i].pts  = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;\n    }\n    dv_extract_audio(buf, c->audio_buf[0], c->audio_buf[1], c->sys);\n    c->abytes += size;\n    size = dv_extract_video_info(c, buf);\n    av_init_packet(pkt);\n    pkt->data     = buf;\n    pkt->size     = size;\n    pkt->flags   |= PKT_FLAG_KEY;\n    pkt->stream_index = c->vst->id;\n    pkt->pts      = c->frames;\n    c->frames++;\n    return size;\n}', 'static inline const DVprofile* dv_frame_profile(const uint8_t* frame)\n{\n    if ((frame[3] & 0x80) == 0) {\n        if ((frame[80*5 + 48 + 3] & 0x4) && (frame[80*5 + 48] == dv_video_source)) {\n            return &dv_profiles[3];\n        } else {\n            return &dv_profiles[0];\n        }\n    } else {\n        if ((frame[80*5 + 48 + 3] & 0x4) && (frame[80*5 + 48] == dv_video_source)) {\n            return &dv_profiles[4];\n        } else if ((frame[5] & 0x07) == 0) {\n            return &dv_profiles[1];\n        } else\n            return &dv_profiles[2];\n    }\n}', 'static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)\n{\n    const uint8_t* as_pack;\n    int freq, stype, smpls, quant, i, ach;\n    as_pack = dv_extract_pack(frame, dv_audio_source);\n    if (!as_pack || !c->sys) {\n        c->ach = 0;\n        return 0;\n    }\n    smpls = as_pack[1] & 0x3f;\n    freq = (as_pack[4] >> 3) & 0x07;\n    stype = (as_pack[3] & 0x1f);\n    quant = as_pack[4] & 0x07;\n    ach = (stype == 2 || (quant && (freq == 2))) ? 2 : 1;\n    for (i=0; i<ach; i++) {\n       if (!c->ast[i]) {\n           c->ast[i] = av_new_stream(c->fctx, 0);\n           if (!c->ast[i])\n               break;\n           av_set_pts_info(c->ast[i], 64, 1, 30000);\n           c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO;\n           c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;\n           av_init_packet(&c->audio_pkt[i]);\n           c->audio_pkt[i].size     = 0;\n           c->audio_pkt[i].data     = c->audio_buf[i];\n           c->audio_pkt[i].stream_index = c->ast[i]->index;\n           c->audio_pkt[i].flags |= PKT_FLAG_KEY;\n       }\n       c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];\n       c->ast[i]->codec->channels = 2;\n       c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;\n       c->ast[i]->start_time = 0;\n    }\n    c->ach = i;\n    return (c->sys->audio_min_samples[freq] + smpls) * 4;  ;\n}', 'static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)\n{\n    int offs;\n    switch (t) {\n    case dv_audio_source:\n          offs = (80*6 + 80*16*3 + 3);\n          break;\n    case dv_audio_control:\n          offs = (80*6 + 80*16*4 + 3);\n          break;\n    case dv_video_control:\n          offs = (80*5 + 48 + 5);\n          break;\n    default:\n          return NULL;\n    }\n    return (frame[offs] == t ? &frame[offs] : NULL);\n}', 'static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,\n                            const DVprofile *sys)\n{\n    int size, chan, i, j, d, of, smpls, freq, quant, half_ch;\n    uint16_t lc, rc;\n    const uint8_t* as_pack;\n    as_pack = dv_extract_pack(frame, dv_audio_source);\n    if (!as_pack)\n        return 0;\n    smpls = as_pack[1] & 0x3f;\n    freq = (as_pack[4] >> 3) & 0x07;\n    quant = as_pack[4] & 0x07;\n    if (quant > 1)\n        return -1;\n    size = (sys->audio_min_samples[freq] + smpls) * 4;\n    half_ch = sys->difseg_size/2;\n    for (chan = 0; chan < sys->n_difchan; chan++) {\n        for (i = 0; i < sys->difseg_size; i++) {\n            frame += 6 * 80;\n            if (quant == 1 && i == half_ch) {\n                if (!pcm2)\n                    break;\n                else\n                    pcm = pcm2;\n            }\n            for (j = 0; j < 9; j++) {\n                for (d = 8; d < 80; d += 2) {\n                    if (quant == 0) {\n                        of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;\n                        if (of*2 >= size)\n                            continue;\n                        pcm[of*2] = frame[d+1];\n                        pcm[of*2+1] = frame[d];\n                        if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)\n                            pcm[of*2+1] = 0;\n                    } else {\n                        lc = ((uint16_t)frame[d] << 4) |\n                             ((uint16_t)frame[d+2] >> 4);\n                        rc = ((uint16_t)frame[d+1] << 4) |\n                             ((uint16_t)frame[d+2] & 0x0f);\n                        lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));\n                        rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));\n                        of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride;\n                        if (of*2 >= size)\n                            continue;\n                        pcm[of*2] = lc & 0xff;\n                        pcm[of*2+1] = lc >> 8;\n                        of = sys->audio_shuffle[i%half_ch+half_ch][j] +\n                            (d - 8)/3 * sys->audio_stride;\n                        pcm[of*2] = rc & 0xff;\n                        pcm[of*2+1] = rc >> 8;\n                        ++d;\n                    }\n                }\n                frame += 16 * 80;\n            }\n        }\n        if(!pcm2)\n            break;\n        pcm = pcm2;\n    }\n    return size;\n}']