[PATCH] lazymanifest: check more return values in filtercopy

Yuya Nishihara yuya at tcha.org
Wed Jan 6 07:56:57 CST 2016


On Wed, 06 Jan 2016 05:58:26 +0000, Martin von Zweigbergk wrote:
> On Tue, Jan 5, 2016 at 8:01 AM Augie Fackler <raf at durin42.com> wrote:
> 
> > # HG changeset patch
> > # User Augie Fackler <raf at durin42.com>
> > # Date 1451586702 18000
> > #      Thu Dec 31 13:31:42 2015 -0500
> > # Node ID 700ae5816d662e0e5dde55c68944329b6eb1b7c0
> > # Parent  0bc71f45d3623b231cc3975b48feccce79d1231e
> > lazymanifest: check more return values in filtercopy
> >
> > Spotted by Bryan O'Sullivan (and vexingly not the static analyzer I've
> > been using.)
> >
> > diff --git a/mercurial/manifest.c b/mercurial/manifest.c
> > --- a/mercurial/manifest.c
> > +++ b/mercurial/manifest.c
> > @@ -707,11 +707,20 @@ static lazymanifest *lazymanifest_filter
> >         copy->pydata = self->pydata;
> >         Py_INCREF(self->pydata);
> >         for (i = 0; i < self->numlines; i++) {
> > -               PyObject *arg = PyString_FromString(self->lines[i].start);
> > -               PyObject *arglist = PyTuple_Pack(1, arg);
> > -               PyObject *result = PyObject_CallObject(matchfn, arglist);
> > +               PyObject *arg = NULL, *arglist = NULL, *result = NULL;
> > +               arg = PyString_FromString(self->lines[i].start);
> > +               if (!arg) {
> > +                       PyErr_SetString(PyExc_TypeError,
> > +                                       "couldn't pack filename");
> >
> 
> TypeError seems wrong here. Most likely out of memory? Should we just leave
> it as whatever it was already set to? We don't set it when PyTuple_Pack()
> below fails.
> 
> 
> > +                       return NULL;
> > +               }
> > +               arglist = PyTuple_Pack(1, arg);
> > +               Py_DECREF(arg);
> > +               if (!arglist) {
> > +                       return NULL;
> > +               }

Perhaps we can use Py_BuildValue("(s)", s) to avoid ugly error handling.

https://docs.python.org/2/c-api/arg.html#c.Py_BuildValue


More information about the Mercurial-devel mailing list