Patchwork [1,of,6,lazymanifest-errors] lazymanifest: check another error return in getitem

login
register
mail settings
Submitter Augie Fackler
Date Dec. 31, 2015, 7:05 p.m.
Message ID <0d56affe821052f6763f.1451588745@imladris.local>
Download mbox | patch
Permalink /patch/12449/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

Augie Fackler - Dec. 31, 2015, 7:05 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1451586967 18000
#      Thu Dec 31 13:36:07 2015 -0500
# Node ID 0d56affe821052f6763f1796341d892c68339fa9
# Parent  7683ed1377dad6ece4dbe2276a8a166c77599a8d
lazymanifest: check another error return in getitem
Yuya Nishihara - Jan. 1, 2016, 9:45 a.m.
On Thu, 31 Dec 2015 14:05:45 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1451586967 18000
> #      Thu Dec 31 13:36:07 2015 -0500
> # Node ID 0d56affe821052f6763f1796341d892c68339fa9
> # Parent  7683ed1377dad6ece4dbe2276a8a166c77599a8d
> lazymanifest: check another error return in getitem
> 
> diff --git a/mercurial/manifest.c b/mercurial/manifest.c
> --- a/mercurial/manifest.c
> +++ b/mercurial/manifest.c
> @@ -394,6 +394,9 @@ static PyObject *lazymanifest_getitem(la
>  		return NULL;
>  	}
>  	needle.start = PyString_AsString(key);
> +	if (!needle.start) {
> +		return NULL;
> +	}

It won't need error return because we do PyString_Check(key) before.

Perhaps we can use PyString_AS_STRING() and PyTuple_GET_ITEM() to clarify
that error handling is omitted explicitly.

I've pushed 4 and 6.

Patch

diff --git a/mercurial/manifest.c b/mercurial/manifest.c
--- a/mercurial/manifest.c
+++ b/mercurial/manifest.c
@@ -394,6 +394,9 @@  static PyObject *lazymanifest_getitem(la
 		return NULL;
 	}
 	needle.start = PyString_AsString(key);
+	if (!needle.start) {
+		return NULL;
+	}
 	hit = bsearch(&needle, self->lines, self->numlines, sizeof(line),
 		      &linecmp);
 	if (!hit || hit->deleted) {