Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-core
Commits
68e11e9a
Commit
68e11e9a
authored
Oct 05, 2018
by
DailyShana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use snprintf
strncpy do not add terminal ‘\0' if the src is too long
parent
3c4fd547
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
interpreter.cpp
interpreter.cpp
+7
-8
interpreter.h
interpreter.h
+4
-3
libdebug.cpp
libdebug.cpp
+1
-1
No files found.
interpreter.cpp
View file @
68e11e9a
...
...
@@ -5,7 +5,6 @@
* Author: Argon
*/
#include <stdio.h>
#include "duel.h"
#include "group.h"
#include "card.h"
...
...
@@ -720,7 +719,7 @@ int32 interpreter::load_script(const char* script_name) {
no_action
++
;
int32
error
=
luaL_loadbuffer
(
current_state
,
(
char
*
)
buffer
,
len
,
script_name
)
||
lua_pcall
(
current_state
,
0
,
0
,
0
);
if
(
error
)
{
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
current_state
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
current_state
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
current_state
,
1
);
no_action
--
;
...
...
@@ -850,7 +849,7 @@ int32 interpreter::call_function(int32 f, uint32 param_count, int32 ret_count) {
call_depth
++
;
push_param
(
current_state
);
if
(
lua_pcall
(
current_state
,
param_count
,
ret_count
,
0
))
{
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
current_state
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
current_state
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
current_state
,
1
);
no_action
--
;
...
...
@@ -890,7 +889,7 @@ int32 interpreter::call_card_function(card* pcard, const char* f, uint32 param_c
lua_remove
(
current_state
,
-
2
);
push_param
(
current_state
);
if
(
lua_pcall
(
current_state
,
param_count
,
ret_count
,
0
))
{
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
current_state
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
current_state
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
current_state
,
1
);
no_action
--
;
...
...
@@ -930,7 +929,7 @@ int32 interpreter::call_code_function(uint32 code, const char* f, uint32 param_c
call_depth
++
;
push_param
(
current_state
);
if
(
lua_pcall
(
current_state
,
param_count
,
ret_count
,
0
))
{
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
current_state
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
current_state
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
current_state
,
1
);
no_action
--
;
...
...
@@ -985,7 +984,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
for
(
int32
i
=
0
;
i
<
extraargs
;
++
i
)
lua_pushvalue
(
current_state
,
(
int32
)(
-
extraargs
-
2
));
if
(
lua_pcall
(
current_state
,
1
+
extraargs
,
1
,
0
))
{
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
current_state
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
current_state
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
current_state
,
1
);
no_action
--
;
...
...
@@ -1016,7 +1015,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
for
(
int32
i
=
0
;
i
<
extraargs
;
++
i
)
lua_pushvalue
(
current_state
,
(
int32
)(
-
extraargs
-
2
));
if
(
lua_pcall
(
current_state
,
1
+
extraargs
,
1
,
0
))
{
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
current_state
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
current_state
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
current_state
,
1
);
no_action
--
;
...
...
@@ -1156,7 +1155,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
return
COROUTINE_YIELD
;
}
else
{
coroutines
.
erase
(
f
);
interpreter
::
strcpy
(
pduel
->
strbuffer
,
lua_tostring
(
rthread
,
-
1
));
sprintf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
rthread
,
-
1
));
handle_message
(
pduel
,
1
);
lua_pop
(
rthread
,
1
);
current_state
=
lua_state
;
...
...
interpreter.h
View file @
68e11e9a
...
...
@@ -15,6 +15,7 @@
#include <unordered_map>
#include <list>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
...
...
@@ -72,9 +73,9 @@ public:
static
void
set_duel_info
(
lua_State
*
L
,
duel
*
pduel
);
static
duel
*
get_duel_info
(
lua_State
*
L
);
template
<
size_t
N
>
static
char
*
strcpy
(
char
(
&
dst
)[
N
],
const
char
*
src
)
{
return
std
::
s
trncpy
(
reinterpret_cast
<
char
*>
(
&
dst
),
src
,
N
);
template
<
size_t
N
,
typename
...
TR
>
static
int
sprintf
(
char
(
&
buffer
)[
N
],
const
char
*
format
,
TR
...
args
)
{
return
std
::
s
nprintf
(
buffer
,
N
,
format
,
args
...
);
}
};
...
...
libdebug.cpp
View file @
68e11e9a
...
...
@@ -18,7 +18,7 @@ int32 scriptlib::debug_message(lua_State *L) {
lua_getglobal
(
L
,
"tostring"
);
lua_pushvalue
(
L
,
-
2
);
lua_pcall
(
L
,
1
,
1
,
0
);
interpreter
::
s
trcpy
(
pduel
->
strbuffer
,
lua_tostring
(
L
,
-
1
));
interpreter
::
s
printf
(
pduel
->
strbuffer
,
"%s"
,
lua_tostring
(
L
,
-
1
));
handle_message
(
pduel
,
2
);
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment