More functions annotated for static analysis

Also more return values checked for values < 0 for errors, instead of
checking == 0 and leaving the positive side unchecked
This commit is contained in:
Daniele Varrazzo 2012-03-01 02:45:48 +00:00
parent 5bfb6cdefe
commit e1266d52cd
6 changed files with 20 additions and 23 deletions

View File

@ -138,12 +138,12 @@ HIDDEN PGcancel *conn_get_cancel(PGconn *pgconn);
HIDDEN void conn_notice_process(connectionObject *self);
HIDDEN void conn_notice_clean(connectionObject *self);
HIDDEN void conn_notifies_process(connectionObject *self);
HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
HIDDEN int conn_connect(connectionObject *self, long int async);
HIDDEN void conn_close(connectionObject *self);
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
RAISES_NEG HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
const char *readonly, const char *deferrable,
int autocommit);
HIDDEN int conn_set_autocommit(connectionObject *self, int value);

View File

@ -332,7 +332,7 @@ exit:
*
* Return 0 on success, else nonzero.
*/
static int
RAISES_NEG static int
conn_read_encoding(connectionObject *self, PGconn *pgconn)
{
char *enc = NULL, *codec = NULL;
@ -468,7 +468,7 @@ conn_is_datestyle_ok(PGconn *pgconn)
/* conn_setup - setup and read basic information about the connection */
int
RAISES_NEG int
conn_setup(connectionObject *self, PGconn *pgconn)
{
PGresult *pgres = NULL;
@ -482,7 +482,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
return -1;
}
if (conn_read_encoding(self, pgconn)) {
if (0 > conn_read_encoding(self, pgconn)) {
return -1;
}
@ -496,7 +496,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
pthread_mutex_lock(&self->lock);
Py_BLOCK_THREADS;
if (psyco_green() && (pq_set_non_blocking(self, 1, 1) != 0)) {
if (psyco_green() && (0 > pq_set_non_blocking(self, 1))) {
return -1;
}
@ -774,7 +774,7 @@ _conn_poll_setup_async(connectionObject *self)
switch (self->status) {
case CONN_STATUS_CONNECTING:
/* Set the connection to nonblocking now. */
if (pq_set_non_blocking(self, 1, 1) != 0) {
if (pq_set_non_blocking(self, 1) != 0) {
break;
}
@ -785,7 +785,7 @@ _conn_poll_setup_async(connectionObject *self)
PyErr_SetString(InterfaceError, "only protocol 3 supported");
break;
}
if (conn_read_encoding(self, self->pgconn)) {
if (0 > conn_read_encoding(self, self->pgconn)) {
break;
}
self->cancel = conn_get_cancel(self->pgconn);
@ -971,7 +971,7 @@ conn_rollback(connectionObject *self)
return res;
}
int
RAISES_NEG int
conn_set_session(connectionObject *self,
const char *isolevel, const char *readonly, const char *deferrable,
int autocommit)

View File

@ -528,7 +528,7 @@ psyco_conn_set_session(connectionObject *self, PyObject *args, PyObject *kwargs)
if (-1 == c_autocommit) { return NULL; }
}
if (0 != conn_set_session(self,
if (0 > conn_set_session(self,
c_isolevel, c_readonly, c_deferrable, c_autocommit)) {
return NULL;
}

View File

@ -726,7 +726,7 @@ _psyco_curs_buildrow(cursorObject *self, int row)
}
if (!t) { goto exit; }
if (0 == _psyco_curs_buildrow_fill(self, t, row, n, istuple)) {
if (0 <= _psyco_curs_buildrow_fill(self, t, row, n, istuple)) {
rv = t;
t = NULL;
}
@ -1347,7 +1347,7 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
Py_INCREF(file);
self->copyfile = file;
if (pq_execute(self, query, 0) == 1) {
if (pq_execute(self, query, 0) >= 0) {
res = Py_None;
Py_INCREF(Py_None);
}
@ -1443,7 +1443,7 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
Py_INCREF(file);
self->copyfile = file;
if (pq_execute(self, query, 0) == 1) {
if (pq_execute(self, query, 0) >= 0) {
res = Py_None;
Py_INCREF(Py_None);
}
@ -1517,7 +1517,7 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs)
self->copyfile = file;
/* At this point, the SQL statement must be str, not unicode */
if (pq_execute(self, Bytes_AS_STRING(sql), 0) == 1) {
if (pq_execute(self, Bytes_AS_STRING(sql), 0) >= 0) {
res = Py_None;
Py_INCREF(res);
}

View File

@ -304,19 +304,16 @@ pq_clear_async(connectionObject *conn)
Accepted arg values are 1 (nonblocking) and 0 (blocking).
Return 0 if everything ok, else nonzero.
In case of error, if pyerr is nonzero, set a Python exception.
Return 0 if everything ok, else < 0 and set an exception.
*/
int
pq_set_non_blocking(connectionObject *conn, int arg, int pyerr)
RAISES_NEG int
pq_set_non_blocking(connectionObject *conn, int arg)
{
int ret = PQsetnonblocking(conn->pgconn, arg);
if (0 != ret) {
Dprintf("PQsetnonblocking(%d) FAILED", arg);
if (pyerr) {
PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
}
PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
ret = -1;
}
return ret;
}

View File

@ -61,7 +61,7 @@ HIDDEN int pq_is_busy(connectionObject *conn);
HIDDEN int pq_is_busy_locked(connectionObject *conn);
HIDDEN int pq_flush(connectionObject *conn);
HIDDEN void pq_clear_async(connectionObject *conn);
HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg, int pyerr);
RAISES_NEG HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg);
HIDDEN void pq_set_critical(connectionObject *conn, const char *msg);