summaryrefslogtreecommitdiff
path: root/psycopg/utils.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-03-01 00:24:52 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-03-01 02:53:28 +0000
commitf2e4a8ed78973a0d14dbe0d463911436562683f3 (patch)
tree8efd13975366068801d43aacb4d5989afe49a2e4 /psycopg/utils.c
parent94327872790cc1649cfe08165d111aa25f045f03 (diff)
downloadpsycopg2-f2e4a8ed78973a0d14dbe0d463911436562683f3.tar.gz
Functions setting exception return a negative value on error
This works around another shortcoming of the static checker; also to be discussed with the author.
Diffstat (limited to 'psycopg/utils.c')
-rw-r--r--psycopg/utils.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/psycopg/utils.c b/psycopg/utils.c
index 4f40cc8..9ae710d 100644
--- a/psycopg/utils.c
+++ b/psycopg/utils.c
@@ -113,20 +113,20 @@ psycopg_escape_identifier_easy(const char *from, Py_ssize_t len)
* Allocate a new buffer on the Python heap containing the new string.
* 'len' is optional: if 0 the length is calculated.
*
- * Return NULL and set an exception in case of error.
+ * Store the return in 'to' and return 0 in case of success, else return -1
+ * and raise an exception.
*/
-char *
-psycopg_strdup(const char *from, Py_ssize_t len)
+CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
+int
+psycopg_strdup(char **to, const char *from, Py_ssize_t len)
{
- char *rv;
-
if (!len) { len = strlen(from); }
- if (!(rv = PyMem_Malloc(len + 1))) {
+ if (!(*to = PyMem_Malloc(len + 1))) {
PyErr_NoMemory();
- return NULL;
+ return -1;
}
- strcpy(rv, from);
- return rv;
+ strcpy(*to, from);
+ return 0;
}
/* Ensure a Python object is a bytes string.