]> granicus.if.org Git - python/commitdiff
Fix Coverity warnings.
authorNeal Norwitz <nnorwitz@gmail.com>
Sat, 27 May 2006 05:21:30 +0000 (05:21 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sat, 27 May 2006 05:21:30 +0000 (05:21 +0000)
 - Check the correct variable (str_obj, not str) for NULL
 - sep_len was already verified it wasn't 0

Objects/stringlib/partition.h
Objects/unicodeobject.c

index 8cc7abeaaf62ac4f5c632f30fb4d1a5554aac659..11a12c6f46dfa04bcbaa9f332177481b24612a47 100644 (file)
@@ -58,7 +58,7 @@ stringlib_rpartition(
     )
 {
     PyObject* out;
-    Py_ssize_t pos;
+    Py_ssize_t pos, j;
 
     if (sep_len == 0) {
         PyErr_SetString(PyExc_ValueError, "empty separator");
@@ -70,17 +70,12 @@ stringlib_rpartition(
        return NULL;
 
     /* XXX - create reversefastsearch helper! */
-    if (sep_len == 0)
-       pos = str_len;
-    else {
-       Py_ssize_t j;
         pos = -1;
        for (j = str_len - sep_len; j >= 0; --j)
             if (STRINGLIB_CMP(str+j, sep, sep_len) == 0) {
                 pos = j;
                 break;
             }
-    }
 
     if (pos < 0) {
        Py_INCREF(str_obj);
index d5935e31df86bac6c878e41064394e32b7fa3b6d..783eb8f2a8a5cc9db973dea9cd586c6505fd9552 100644 (file)
@@ -3955,7 +3955,7 @@ Py_ssize_t PyUnicode_Find(PyObject *str,
     PyUnicodeObject* sub_obj;
 
     str_obj = (PyUnicodeObject*) PyUnicode_FromObject(str);
-    if (!str)
+    if (!str_obj)
        return -2;
     sub_obj = (PyUnicodeObject*) PyUnicode_FromObject(substr);
     if (!sub_obj) {