Check return values of a few function calls.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 23 Jan 2015 15:40:34 +0000 (17:40 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 23 Jan 2015 16:45:07 +0000 (18:45 +0200)
While we're at it, fix spelling of the error messages.

Clang static analyzer complained.

convert.c
info.c
statement.c

index f6f88cdde36e1f8eaa3a46b06d672e4262911512..3ed6ee326b533ed2b293bed70e1331333760f585 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -4624,6 +4624,7 @@ mylog("cvt_null_date_string=%d pgtype=%d buf=%p\n", conn->connInfo.cvt_null_date
            else
            {
                BOOL    is_in_trans_at_entry = CC_is_in_trans(conn);
+               int     write_result;
 
                /* begin transaction if needed */
                if (!is_in_trans_at_entry)
@@ -4642,7 +4643,7 @@ mylog("cvt_null_date_string=%d pgtype=%d buf=%p\n", conn->connInfo.cvt_null_date
                if (lobj_oid == 0)
                {
                    qb->errornumber = STMT_EXEC_ERROR;
-                   qb->errormsg = "Couldnt create (in-line) large object.";
+                   qb->errormsg = "Couldn't create (in-line) large object.";
                    retval = SQL_ERROR;
                    goto cleanup;
                }
@@ -4652,12 +4653,19 @@ mylog("cvt_null_date_string=%d pgtype=%d buf=%p\n", conn->connInfo.cvt_null_date
                if (lobj_fd < 0)
                {
                    qb->errornumber = STMT_EXEC_ERROR;
-                   qb->errormsg = "Couldnt open (in-line) large object for writing.";
+                   qb->errormsg = "Couldn't open (in-line) large object for writing.";
                    retval = SQL_ERROR;
                    goto cleanup;
                }
 
-               retval = odbc_lo_write(conn, lobj_fd, buffer, (Int4) used);
+               write_result = odbc_lo_write(conn, lobj_fd, buffer, (Int4) used);
+               if (write_result < 0)
+               {
+                   qb->errornumber = STMT_EXEC_ERROR;
+                   qb->errormsg = "Couldn't write to (in-line) large object.";
+                   retval = SQL_ERROR;
+                   goto cleanup;
+               }
 
                odbc_lo_close(conn, lobj_fd);
 
diff --git a/info.c b/info.c
index e1ee8776f495bf28626577921cf1bd4a5c9faf78..00389b162890871daaaab8f7e35f56b095c5a5ff 100644 (file)
--- a/info.c
+++ b/info.c
@@ -46,8 +46,6 @@
 #define TRIGGER_DELETE 0x01
 #define TRIGGER_UPDATE 0x02
 
-#define    NULL_IF_NULL(a) ((a) ? ((const char *) a) : "(NULL)")
-
 /* extern GLOBAL_VALUES globals; */
 
 static const SQLCHAR *pubstr = (SQLCHAR *) "public";
index c3a6e3d462101e76f9a2f27ddaf6e535301c12be..a141f35ad23ae227aa7656bb46ad3e6d2eff8b0a 100644 (file)
@@ -2545,7 +2545,14 @@ libpq_bind_and_exec(StatementClass *stmt)
        res = NULL;
 
    if (!res)
+   {
        newres = res = QR_Constructor();
+       if (!res)
+       {
+           SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Out of memory while allocating result set", func);
+           goto cleanup;
+       }
+   }
 
    /* 3. Receive results */
 inolog("get_Result=%p %p %d\n", res, SC_get_Result(stmt), stmt->curr_param_result);