Use CheckExact for strings.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 15 May 2009 15:35:03 +0000 (17:35 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 15 May 2009 15:35:03 +0000 (17:35 +0200)
dulwich/_objects.c
dulwich/_pack.c

index bad0297400336b4ae9a1460ad71187da0aaeb676..f213b1b77adfd80fd4fcf1c1bf26086d6cc663e0 100644 (file)
@@ -28,7 +28,7 @@ static PyObject *py_hex_to_sha(PyObject *self, PyObject *py_hexsha)
        char sha[20];
        int i;
 
-       if (!PyString_Check(py_hexsha)) {
+       if (!PyString_CheckExact(py_hexsha)) {
                PyErr_SetString(PyExc_TypeError, "hex sha is not a string");
                return NULL;
        }
@@ -61,7 +61,7 @@ static PyObject *sha_to_pyhex(const unsigned char *sha)
 
 static PyObject *py_sha_to_hex(PyObject *self, PyObject *py_sha)
 {
-       if (!PyString_Check(py_sha)) {
+       if (!PyString_CheckExact(py_sha)) {
                PyErr_SetString(PyExc_TypeError, "sha is not a string");
                return NULL;
        }
@@ -116,7 +116,11 @@ static PyObject *py_parse_tree(PyObject *self, PyObject *args)
                        Py_DECREF(name);
             return NULL;
         }
-               PyDict_SetItem(ret, name, item);
+               if (PyDict_SetItem(ret, name, item) == -1) {
+                       Py_DECREF(ret);
+                       Py_DECREF(item);
+                       return NULL;
+               }
                Py_DECREF(name);
                Py_DECREF(item);
 
index 5f15c7f6257fe79fdbd79fbd87601f88d72d4b1a..55fa09d084977a66938606370fe2a19aed42d5fc 100644 (file)
@@ -22,7 +22,7 @@
 
 static int py_is_sha(PyObject *sha)
 {
-    if (!PyString_Check(sha))
+    if (!PyString_CheckExact(sha))
         return 0;
 
     if (PyString_Size(sha) != 20)