Patchwork [2,of,6,lazymanifest-errors] lazymanifest: check another error return in delitem

login
register
mail settings
Submitter Augie Fackler
Date Dec. 31, 2015, 7:05 p.m.
Message ID <2cde05d091f1e053f4cf.1451588746@imladris.local>
Download mbox | patch
Permalink /patch/12450/
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 1451587231 18000
#      Thu Dec 31 13:40:31 2015 -0500
# Node ID 2cde05d091f1e053f4cf57db579acdd98b8935cf
# Parent  0d56affe821052f6763f1796341d892c68339fa9
lazymanifest: check another error return in delitem
Bryan O'Sullivan - Jan. 1, 2016, 10:53 p.m.
On Thu, Dec 31, 2015 at 11:05 AM, Augie Fackler <raf@durin42.com> wrote:

>         needle.start = PyString_AsString(key);
> +       if (!needle.start) {
> +               return -1;
> +       }
>

This check is unnecessary as you've already done a PyString_Check a few
lines earlier.

In fact you can and should use PyString_AS_STRING for efficiency here
instead.

Patch

diff --git a/mercurial/manifest.c b/mercurial/manifest.c
--- a/mercurial/manifest.c
+++ b/mercurial/manifest.c
@@ -416,6 +416,9 @@  static int lazymanifest_delitem(lazymani
 		return -1;
 	}
 	needle.start = PyString_AsString(key);
+	if (!needle.start) {
+		return -1;
+	}
 	hit = bsearch(&needle, self->lines, self->numlines, sizeof(line),
 		      &linecmp);
 	if (!hit || hit->deleted) {