diff options
author | randomdan <randomdan@localhost> | 2010-04-02 01:05:25 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-04-02 01:05:25 +0000 |
commit | 1ede41e012f7363a0d2804e70be0f6c772997e82 (patch) | |
tree | 86671e425d8f66fa16ce1989dbdc4fac45853295 /libodbcpp/error.cpp | |
parent | Lots of little fixes (diff) | |
download | libdbpp-odbc-1ede41e012f7363a0d2804e70be0f6c772997e82.tar.bz2 libdbpp-odbc-1ede41e012f7363a0d2804e70be0f6c772997e82.tar.xz libdbpp-odbc-1ede41e012f7363a0d2804e70be0f6c772997e82.zip |
lots of gcc warning fixes and a few newbies
Diffstat (limited to 'libodbcpp/error.cpp')
-rw-r--r-- | libodbcpp/error.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/libodbcpp/error.cpp b/libodbcpp/error.cpp index 5497f4d..3d55fc2 100644 --- a/libodbcpp/error.cpp +++ b/libodbcpp/error.cpp @@ -13,29 +13,45 @@ odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * SQLCHAR sqlerrmsg[12800]; char * action; - vasprintf(&action, actionfmt, ap); + if (vasprintf(&action, actionfmt, ap) < 0) { + syslog(LOG_WARNING, "%s: %d: %ld: %5.5s: \"%s\" : failed to malloc for vasprintf", + __FUNCTION__, err, sqlerr, sqlstatus, sqlerrmsg); + return; + } SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, sizeof(sqlerrmsg), NULL); switch (rc) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - asprintf(msg, "%d: %ld: %5.5s: \"%s\" while attempting to %s", - err, sqlerr, sqlstatus, sqlerrmsg, action); + if (msg) { + if (asprintf(msg, "%d: %ld: %5.5s: \"%s\" while attempting to %s", + err, sqlerr, sqlstatus, sqlerrmsg, action) < 1) { + *msg = NULL; + } + } syslog(LOG_WARNING, "%s: %d: %ld: %5.5s: \"%s\" while attempting to %s", __FUNCTION__, err, sqlerr, sqlstatus, sqlerrmsg, action); break; case SQL_INVALID_HANDLE: - asprintf(msg, "(%d) Invalid handle passed into function trying to %s.", - err, action); + if (msg) { + if (asprintf(msg, "(%d) Invalid handle passed into function trying to %s.", + err, action) < 1) { + *msg = NULL; + } + } syslog(LOG_ERR, "%s: (%d) Invalid handle passed into function trying to %s.", __FUNCTION__, err, action); break; case SQL_NO_DATA: - asprintf(msg, "(%d) No error data available for record trying to %s.", - err, action); + if (msg) { + if (asprintf(msg, "(%d) No error data available for record trying to %s.", + err, action) < 1) { + *msg = NULL; + } + } syslog(LOG_ERR, "%s: (%d) No error data available for record trying to %s.", __FUNCTION__, err, action); break; @@ -62,8 +78,10 @@ ODBC::Error::Error(char const * action, ...) va_list ap; va_start(ap, action); - vsyslog(LOG_ERR, action, ap); - vasprintf(&msg, action, ap); + vsyslog(LOG_ERR, action, ap); + if (vasprintf(&msg, action, ap) < 1) { + msg = NULL; + } va_end(ap); } |