Quellcode durchsuchen

Use CheckExact for strings.

Jelmer Vernooij vor 16 Jahren
Ursprung
Commit
3bb18d219a
2 geänderte Dateien mit 8 neuen und 4 gelöschten Zeilen
  1. 7 3
      dulwich/_objects.c
  2. 1 1
      dulwich/_pack.c

+ 7 - 3
dulwich/_objects.c

@@ -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);
 

+ 1 - 1
dulwich/_pack.c

@@ -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)