summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-19 21:40:53 +0100
committerHaru <haru@dotalux.com>2016-03-20 18:32:07 +0100
commit127093b5327de343f4ae3f7c8752c465eea911c8 (patch)
treeaad51f53ba9bb8b99aa55a902ab1353a1937b403
parentf4fced20c769ccee7f808531221dda481f7bbcca (diff)
downloadhercules-127093b5327de343f4ae3f7c8752c465eea911c8.tar.gz
hercules-127093b5327de343f4ae3f7c8752c465eea911c8.tar.bz2
hercules-127093b5327de343f4ae3f7c8752c465eea911c8.tar.xz
hercules-127093b5327de343f4ae3f7c8752c465eea911c8.zip
Changed buffer argument of SQL->StmtBindParam() to const
Parameters are supposed to be read-only Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--src/char/char.c4
-rw-r--r--src/char/int_homun.c4
-rw-r--r--src/common/sql.c19
-rw-r--r--src/common/sql.h2
-rw-r--r--src/login/account_sql.c62
-rw-r--r--src/map/log.c16
6 files changed, 58 insertions, 49 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 23f5d1ea0..df59eafc9 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -3298,8 +3298,8 @@ void char_ban(int account_id, int char_id, time_t *unban_time, short year, short
if( SQL_SUCCESS != SQL->StmtPrepare(stmt,
"UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
char_db)
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_LONG, (void*)&timestamp, sizeof(timestamp))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_INT, (void*)&char_id, sizeof(char_id))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_LONG, &timestamp, sizeof(timestamp))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_INT, &char_id, sizeof(char_id))
|| SQL_SUCCESS != SQL->StmtExecute(stmt)
) {
SqlStmt_ShowDebug(stmt);
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index bfb0009e6..90643699c 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -171,8 +171,8 @@ bool mapif_homunculus_save(const struct s_homunculus *hd)
} else {
for (i = 0; i < MAX_HOMUNSKILL; ++i) {
if (hd->hskill[i].id > 0 && hd->hskill[i].lv != 0) {
- SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, (void*)&hd->hskill[i].id, 0); // FIXME: StmtBindParam should take const void
- SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, (void*)&hd->hskill[i].lv, 0); // FIXME: StmtBindParam should take const void
+ SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, &hd->hskill[i].id, 0);
+ SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, &hd->hskill[i].lv, 0);
if (SQL_ERROR == SQL->StmtExecute(stmt)) {
SqlStmt_ShowDebug(stmt);
flag = false;
diff --git a/src/common/sql.c b/src/common/sql.c
index 1dcf5d374..65960d8ea 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -629,7 +629,7 @@ size_t SqlStmt_NumParams(struct SqlStmt *self)
}
/// Binds a parameter to a buffer.
-int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len)
+int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len)
{
if( self == NULL )
return SQL_ERROR;
@@ -650,10 +650,19 @@ int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_
self->params[i].buffer_type = MYSQL_TYPE_NULL;
self->bind_params = true;
}
- if( idx < self->max_params )
- return Sql_P_BindSqlDataType(self->params+idx, buffer_type, buffer, buffer_len, NULL, NULL);
- else
- return SQL_SUCCESS;// out of range - ignore
+ if (idx >= self->max_params)
+ return SQL_SUCCESS; // out of range - ignore
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+ /*
+ * MySQL uses the same struct with a non-const buffer for both
+ * parameters (input) and columns (output).
+ * As such, we get to close our eyes and pretend we didn't see we're
+ * dropping a const qualifier here.
+ */
+ return Sql_P_BindSqlDataType(self->params+idx, buffer_type, (void *)buffer, buffer_len, NULL, NULL);
+#pragma GCC diagnostic pop
}
/// Executes the prepared statement.
diff --git a/src/common/sql.h b/src/common/sql.h
index 3619895b1..07be829fc 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -209,7 +209,7 @@ struct sql_interface {
/// All parameters should have bindings.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len);
+ int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len);
/// Executes the prepared statement.
/// Any previous result is freed and all column bindings are removed.
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index 6d0e795f6..195a10233 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -644,22 +644,22 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
if( SQL_SUCCESS != SQL->StmtPrepare(stmt,
"INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
db->account_db)
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_INT, (void*)&acc->account_id, sizeof(acc->account_id))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, (void*)&acc->email, strlen(acc->email))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_INT, (void*)&acc->group_id, sizeof(acc->group_id))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_UINT, (void*)&acc->state, sizeof(acc->state))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, (void*)&acc->unban_time, sizeof(acc->unban_time))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_INT, (void*)&acc->expiration_time, sizeof(acc->expiration_time))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_UINT, (void*)&acc->logincount, sizeof(acc->logincount))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, (void*)&acc->lastlogin, strlen(acc->lastlogin))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, (void*)&acc->last_ip, strlen(acc->last_ip))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_STRING, (void*)&acc->birthdate, strlen(acc->birthdate))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_UCHAR, (void*)&acc->char_slots, sizeof(acc->char_slots))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_STRING, (void*)&acc->pincode, strlen(acc->pincode))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 15, SQLDT_LONG, (void*)&acc->pincode_change, sizeof(acc->pincode_change))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_INT, &acc->account_id, sizeof(acc->account_id))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->userid, strlen(acc->userid))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, acc->pass, strlen(acc->pass))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_ENUM, &acc->sex, sizeof(acc->sex))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, &acc->email, strlen(acc->email))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_INT, &acc->group_id, sizeof(acc->group_id))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_UINT, &acc->state, sizeof(acc->state))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, &acc->unban_time, sizeof(acc->unban_time))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_INT, &acc->expiration_time, sizeof(acc->expiration_time))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_UINT, &acc->logincount, sizeof(acc->logincount))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_UCHAR, &acc->char_slots, sizeof(acc->char_slots))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_STRING, &acc->pincode, strlen(acc->pincode))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 15, SQLDT_LONG, &acc->pincode_change, sizeof(acc->pincode_change))
|| SQL_SUCCESS != SQL->StmtExecute(stmt)
) {
SqlStmt_ShowDebug(stmt);
@@ -667,21 +667,21 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
}
} else {// update account table
if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?,`pincode_change`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id)
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, (void*)acc->email, strlen(acc->email))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_INT, (void*)&acc->group_id, sizeof(acc->group_id))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_UINT, (void*)&acc->state, sizeof(acc->state))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_LONG, (void*)&acc->unban_time, sizeof(acc->unban_time))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, (void*)&acc->expiration_time, sizeof(acc->expiration_time))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_UINT, (void*)&acc->logincount, sizeof(acc->logincount))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_STRING, (void*)&acc->lastlogin, strlen(acc->lastlogin))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, (void*)&acc->last_ip, strlen(acc->last_ip))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, (void*)&acc->birthdate, strlen(acc->birthdate))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_UCHAR, (void*)&acc->char_slots, sizeof(acc->char_slots))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_STRING, (void*)&acc->pincode, strlen(acc->pincode))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_LONG, (void*)&acc->pincode_change, sizeof(acc->pincode_change))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, acc->userid, strlen(acc->userid))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->pass, strlen(acc->pass))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_ENUM, &acc->sex, sizeof(acc->sex))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, acc->email, strlen(acc->email))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_INT, &acc->group_id, sizeof(acc->group_id))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_UINT, &acc->state, sizeof(acc->state))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_LONG, &acc->unban_time, sizeof(acc->unban_time))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, &acc->expiration_time, sizeof(acc->expiration_time))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_UINT, &acc->logincount, sizeof(acc->logincount))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_UCHAR, &acc->char_slots, sizeof(acc->char_slots))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_STRING, &acc->pincode, strlen(acc->pincode))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_LONG, &acc->pincode_change, sizeof(acc->pincode_change))
|| SQL_SUCCESS != SQL->StmtExecute(stmt)
) {
SqlStmt_ShowDebug(stmt);
diff --git a/src/map/log.c b/src/map/log.c
index 245229a15..c19190d90 100644
--- a/src/map/log.c
+++ b/src/map/log.c
@@ -289,7 +289,7 @@ void log_atcommand_sub_sql(struct map_session_data* sd, const char* message)
stmt = SQL->StmtMalloc(logs->mysql_handle);
if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_gm, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, message, safestrnlen(message, 255))
|| SQL_SUCCESS != SQL->StmtExecute(stmt) )
{
SqlStmt_ShowDebug(stmt);
@@ -331,11 +331,11 @@ void log_npc_sub_sql(struct map_session_data *sd, const char *message)
nullpo_retv(sd);
nullpo_retv(message);
stmt = SQL->StmtMalloc(logs->mysql_handle);
- if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
- || SQL_SUCCESS != SQL->StmtExecute(stmt) )
- {
+ if (SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, message, safestrnlen(message, 255))
+ || SQL_SUCCESS != SQL->StmtExecute(stmt)
+ ) {
SqlStmt_ShowDebug(stmt);
SQL->StmtFree(stmt);
return;
@@ -388,8 +388,8 @@ void log_chat_sub_sql(e_log_chat_type type, int type_id, int src_charid, int src
nullpo_retv(message);
stmt = SQL->StmtMalloc(logs->mysql_handle);
if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", logs->config.log_chat, logs->chattype2char(type), type_id, src_charid, src_accid, mapname, x, y)
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH))
- || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, dst_charname, safestrnlen(dst_charname, NAME_LENGTH))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, message, safestrnlen(message, CHAT_SIZE_MAX))
|| SQL_SUCCESS != SQL->StmtExecute(stmt)
) {
SqlStmt_ShowDebug(stmt);