Skip to content

Commit

Permalink
safer string functions (#15)
Browse files Browse the repository at this point in the history
replaced unsafe/depreciated functions
  • Loading branch information
Ownasaurus authored and noah- committed Nov 19, 2018
1 parent 878ceb2 commit 528f59c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
20 changes: 10 additions & 10 deletions Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool __fastcall KeyEventCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup(name);
evt->name = _strdup(name);
evt->arg1 = new DWORD((DWORD)helper->key);

script->FireEvent(evt);
Expand All @@ -57,7 +57,7 @@ bool __fastcall KeyEventCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup(name);
evt->name = _strdup(name);
evt->arg1 = new DWORD((DWORD)helper->key);
evt->arg4 = new DWORD(false);
ResetEvent(Vars.eventSignal);
Expand Down Expand Up @@ -88,7 +88,7 @@ bool __fastcall PlayerAssignCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("playerassign");
evt->name = _strdup("playerassign");
evt->arg1 = new DWORD((DWORD)helper->arg1);

script->FireEvent(evt);
Expand All @@ -107,7 +107,7 @@ bool __fastcall MouseClickCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("mouseclick");
evt->name = _strdup("mouseclick");
evt->arg1 = new DWORD(helper->arg1);
evt->arg2 = new DWORD(helper->arg2);
evt->arg3 = new DWORD(helper->arg3);
Expand All @@ -129,7 +129,7 @@ bool __fastcall MouseMoveCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("mousemove");
evt->name = _strdup("mousemove");
evt->arg1 = new DWORD(helper->arg1);
evt->arg2 = new DWORD(helper->arg2);

Expand All @@ -152,7 +152,7 @@ bool __fastcall BCastEventCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("scriptmsg");
evt->name = _strdup("scriptmsg");
evt->arg1 = new DWORD(argc);
evt->argv = new JSAutoStructuredCloneBuffer*;
for (uint i = 0; i < argc; i++) {
Expand Down Expand Up @@ -231,7 +231,7 @@ bool __fastcall CopyDataCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("copydata");
evt->name = _strdup("copydata");
evt->arg1 = new DWORD(helper->mode);
evt->arg2 = _strdup(helper->msg);

Expand All @@ -251,7 +251,7 @@ bool __fastcall ItemEventCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("itemaction");
evt->name = _strdup("itemaction");
evt->arg1 = new DWORD(helper->id);
evt->arg2 = _strdup(helper->code);
evt->arg3 = new DWORD(helper->mode);
Expand All @@ -273,7 +273,7 @@ bool __fastcall GameActionEventCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup("gameevent");
evt->name = _strdup("gameevent");
evt->arg1 = new BYTE(helper->mode);
evt->arg2 = new DWORD(helper->param1);
evt->arg3 = new DWORD(helper->param2);
Expand All @@ -298,7 +298,7 @@ bool __fastcall PacketEventCallback(Script* script, void* argv, uint argc) {
Event* evt = new Event;
evt->owner = script;
evt->argc = argc;
evt->name = strdup(helper->name);
evt->name = _strdup(helper->name);
evt->arg1 = new BYTE[helper->dwSize];
evt->arg2 = new DWORD(helper->dwSize);
evt->arg4 = new DWORD(false);
Expand Down
4 changes: 3 additions & 1 deletion File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ FILE* fileOpenRelScript(const char* filename, const char* mode, JSContext* cx) {

// Open the file
if (fopen_s(&f, fullPath, mode) != 0 || f == NULL) {
JS_ReportError(cx, "Couldn't open file %s: %s", filename, _strerror(NULL));
char message[128];
_strerror_s(message, 128, NULL);
JS_ReportError(cx, "Couldn't open file %s: %s", filename, message);
return NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions JSCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ JSAPI_FUNC(my_setTimeout) {
self->RegisterEvent("setTimeout", JS_ARGV(cx, vp)[0]);
Event* evt = new Event;
evt->owner = self;
evt->name = strdup("setTimeout");
evt->name = _strdup("setTimeout");
evt->arg3 = new jsval(JS_ARGV(cx, vp)[0]);
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(ScriptEngine::AddDelayedEvent(evt, freq)));
}
Expand All @@ -111,7 +111,7 @@ JSAPI_FUNC(my_setInterval) {
self->RegisterEvent("setInterval", JS_ARGV(cx, vp)[0]);
Event* evt = new Event;
evt->owner = self;
evt->name = strdup("setInterval");
evt->name = _strdup("setInterval");
evt->arg3 = new jsval(JS_ARGV(cx, vp)[0]);
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(ScriptEngine::AddDelayedEvent(evt, freq)));
}
Expand Down

0 comments on commit 528f59c

Please sign in to comment.