1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Fix for CONC-624:

- ER() macro now checks if the error code is known, if not it will return
  "Unknown or undefined error code" (instead of crashing)
- SET_CLIENT_STMT_ERROR now maps to stmt_set_error and accepts variadic
  arguments
This commit is contained in:
Georg Richter
2023-01-15 14:11:54 +01:00
parent b9e9758e93
commit bf82b2d8cb
7 changed files with 97 additions and 34 deletions

View File

@@ -1851,7 +1851,7 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name)
{
MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data;
stmt->mysql= NULL;
SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, function_name);
SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, 0, function_name);
}
mysql->stmts= NULL;
}
@@ -2049,18 +2049,20 @@ void my_set_error(MYSQL *mysql,
const char *errmsg;
if (!format)
{
if (error_nr >= CR_MIN_ERROR && error_nr <= CR_MYSQL_LAST_ERROR)
errmsg= ER(error_nr);
else if (error_nr >= CER_MIN_ERROR && error_nr <= CR_MARIADB_LAST_ERROR)
errmsg= CER(error_nr);
else
errmsg= ER(CR_UNKNOWN_ERROR);
}
mysql->net.last_errno= error_nr;
ma_strmake(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH);
if (!format)
{
if (IS_MYSQL_ERROR(error_nr) || IS_MARIADB_ERROR(error_nr))
errmsg= ER(error_nr);
else {
snprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE - 1,
ER_UNKNOWN_ERROR_CODE, error_nr);
return;
}
}
va_start(ap, format);
vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE - 1,
format ? format : errmsg, ap);