Commit 9e7c8ca8 authored by VanillaSalt's avatar VanillaSalt

use strncpy() instead of sprintf()

parent 034105cc
...@@ -645,7 +645,7 @@ int32 interpreter::load_script(char* script_name) { ...@@ -645,7 +645,7 @@ int32 interpreter::load_script(char* script_name) {
no_action++; no_action++;
error = luaL_loadbuffer(current_state, (const char*) buffer, len, (const char*) script_name) || lua_pcall(current_state, 0, 0, 0); error = luaL_loadbuffer(current_state, (const char*) buffer, len, (const char*) script_name) || lua_pcall(current_state, 0, 0, 0);
if (error) { if (error) {
sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
...@@ -780,7 +780,7 @@ int32 interpreter::call_function(int32 f, uint32 param_count, uint32 ret_count) ...@@ -780,7 +780,7 @@ int32 interpreter::call_function(int32 f, uint32 param_count, uint32 ret_count)
call_depth++; call_depth++;
push_param(current_state); push_param(current_state);
if (lua_pcall(current_state, param_count, ret_count, 0)) { if (lua_pcall(current_state, param_count, ret_count, 0)) {
sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
...@@ -820,7 +820,7 @@ int32 interpreter::call_card_function(card* pcard, char* f, uint32 param_count, ...@@ -820,7 +820,7 @@ int32 interpreter::call_card_function(card* pcard, char* f, uint32 param_count,
lua_remove(current_state, -2); lua_remove(current_state, -2);
push_param(current_state); push_param(current_state);
if (lua_pcall(current_state, param_count, ret_count, 0)) { if (lua_pcall(current_state, param_count, ret_count, 0)) {
sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
...@@ -860,7 +860,7 @@ int32 interpreter::call_code_function(uint32 code, char* f, uint32 param_count, ...@@ -860,7 +860,7 @@ int32 interpreter::call_code_function(uint32 code, char* f, uint32 param_count,
call_depth++; call_depth++;
push_param(current_state); push_param(current_state);
if (lua_pcall(current_state, param_count, ret_count, 0)) { if (lua_pcall(current_state, param_count, ret_count, 0)) {
sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
...@@ -917,7 +917,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) { ...@@ -917,7 +917,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
for(int32 i = 0; i < extraargs; ++i) for(int32 i = 0; i < extraargs; ++i)
lua_pushvalue(current_state, (int32)(-extraargs - 2)); lua_pushvalue(current_state, (int32)(-extraargs - 2));
if (lua_pcall(current_state, 1 + extraargs, 1, 0)) { if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
...@@ -949,7 +949,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg ...@@ -949,7 +949,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
for(int32 i = 0; i < extraargs; ++i) for(int32 i = 0; i < extraargs; ++i)
lua_pushvalue(current_state, (int32)(-extraargs - 2)); lua_pushvalue(current_state, (int32)(-extraargs - 2));
if (lua_pcall(current_state, 1 + extraargs, 1, 0)) { if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
...@@ -1059,7 +1059,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va ...@@ -1059,7 +1059,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
return COROUTINE_YIELD; return COROUTINE_YIELD;
} else { } else {
coroutines.erase(f); coroutines.erase(f);
sprintf(pduel->strbuffer, lua_tostring(rthread, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(rthread, -1));
handle_message(pduel, 1); handle_message(pduel, 1);
lua_pop(rthread, 1); lua_pop(rthread, 1);
current_state = lua_state; current_state = lua_state;
......
...@@ -73,6 +73,11 @@ public: ...@@ -73,6 +73,11 @@ public:
static int32 get_function_handle(lua_State* L, int32 index); static int32 get_function_handle(lua_State* L, int32 index);
static void set_duel_info(lua_State* L, duel* pduel); static void set_duel_info(lua_State* L, duel* pduel);
static duel* get_duel_info(lua_State* L); static duel* get_duel_info(lua_State* L);
template <size_t N>
static char* strcpy(char (&src)[N], const char *dst) {
return strncpy(reinterpret_cast<char*>(&src), dst, N);
}
}; };
#define PARAM_TYPE_INT 0x01 #define PARAM_TYPE_INT 0x01
......
...@@ -18,7 +18,7 @@ int32 scriptlib::debug_message(lua_State *L) { ...@@ -18,7 +18,7 @@ int32 scriptlib::debug_message(lua_State *L) {
lua_getglobal(L, "tostring"); lua_getglobal(L, "tostring");
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_pcall(L, 1, 1, 0); lua_pcall(L, 1, 1, 0);
sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1)); interpreter::strcpy(pduel->strbuffer, lua_tostring(L, -1));
handle_message(pduel, 2); handle_message(pduel, 2);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment