[FFmpeg-devel] [PATCH] urlconcat protocol

Michael Niedermayer michaelni
Fri Feb 5 04:28:35 CET 2010


On Fri, Feb 05, 2010 at 12:11:40AM +0100, Michele Orr? wrote:
[...]
> +static int urlconcat_close(URLContext *h)
> +{
> +    int err = 0;
> +    size_t i;
> +    struct urlconcat_data *udata  = h->priv_data;
> +    struct urlconcat_nodes *unodes = udata->nodes;
> +
> +    for (i=0; i != udata->length; i++)
> +       err |= url_close(unodes[i].uc) < 0 ? -1 : 0;

> +    av_free(unodes);
> +    av_free(udata);
> +    h->priv_data = NULL;

av_freep(&udata->nodes);
av_freep(&h->priv_data);



> +    return err;
> +}
> +
> +static int urlconcat_open(URLContext *h, const char *uri, int flags)
> +{
> +    char *urinod = NULL, *tmpunod;
> +    int err = 0;
> +    int64_t size;
> +    size_t  len, i;
> +    URLContext *uc;
> +    struct urlconcat_data *udata;
> +    struct urlconcat_nodes *unodes;
> +
> +    av_strstart(uri, "cat:", &uri);
> +
> +    /* creating udata */
> +    if (!(udata = av_mallocz(sizeof(*udata))))
> +        return AVERROR(ENOMEM);
> +    h->priv_data = udata;
> +    /* creating udata->nodes */
> +    for (i=0, len = 1; uri[i]; i++)  /* cat:[url]|[url] -> nodes = sep+1 */
> +        if (uri[i] == *AV_CAT_SEPARATOR)
> +            /* integer overflow */
> +            if (++len == UINT_MAX / sizeof(*unodes)) {

> +                av_free(udata);
> +                h->priv_data = NULL;

av_freep(&h->priv_data);


> +                return AVERROR(ENAMETOOLONG);
> +            }
> +    if (!(unodes = av_malloc(sizeof(*unodes) * len))) {
> +        av_free(udata);
> +        h->priv_data = NULL;
> +        return AVERROR(ENOMEM);
> +    } else
> +        udata->nodes = unodes;
> +
> +    /* handle input */
> +    if (!*uri) 
> +        err = AVERROR(ENOENT);
> +    for (i = 0; *uri; i++) {
> +        /* parsing uri */
> +        len = strcspn(uri, AV_CAT_SEPARATOR);
> +        if (!(tmpunod = av_realloc(urinod, len+1))) {
> +            err = AVERROR(ENOMEM);
> +            break;

> +        } else 

trailing whitespace is forbidden in our svn
maybe you want to try our patcheck script (see tools directory in svn)


> +            urinod = tmpunod;
> +        av_strlcpy(urinod, uri, len+1);
> +        uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
> +        /* creating URLContext */
> +        if ((err = url_open(&uc, urinod, flags)) < 0)
> +            break;
> +        /* creating size */
> +        size = url_filesize(uc);
> +        if (size < 0) {
> +            err = AVERROR(ENOSYS);
> +            break;
> +        }
> +        /* assembling */
> +        unodes[i].uc   = uc;
> +        unodes[i].size = size;
> +    }
> +    av_free(urinod);
> +    udata->length = i;

> +    if (err < 0) 
> +        urlconcat_close(h);
> +    else
> +        unodes = av_realloc(unodes, udata->length * sizeof(*unodes));
> +    return err;

the new array isnt stored anywhere and the failure cases is not handled

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100205/f1d5715d/attachment.pgp>



More information about the ffmpeg-devel mailing list