From 3aaaf700f0feb3c8ef8c7d9854538f88bb3c5648 Mon Sep 17 00:00:00 2001 From: Marqt Date: Tue, 14 Jun 2016 21:38:19 +0200 Subject: [PATCH] Probably a fix for issue #87 Former-commit-id: dbcb2b2160f5c02e8228ae8b6ca63947cf676796 --- src/vizdoom/src/vizdoom_input.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/vizdoom/src/vizdoom_input.cpp b/src/vizdoom/src/vizdoom_input.cpp index 9bc0d6c43..ceccd5f6c 100644 --- a/src/vizdoom/src/vizdoom_input.cpp +++ b/src/vizdoom/src/vizdoom_input.cpp @@ -103,7 +103,7 @@ bool ViZDoom_CommmandFilter(const char *cmd){ delete[] ckeckCmd; } - //printf("%d %s\n",gametic, cmd); + //Printf("%d %s\n", gametic, cmd); return true; } @@ -220,13 +220,18 @@ void ViZDoom_ResetDiscontinuousBT(){ } char* ViZDoom_AddStateToBTCommmand(char *& cmd, int state){ - char *stateCmd = new char[strlen(cmd)+1]; - if (state) stateCmd[0] = '+'; + size_t cmdLen = strlen(cmd); + char *stateCmd = new char[cmdLen + 2]; + if (state != 0) stateCmd[0] = '+'; else stateCmd[0] = '-'; - strcpy(stateCmd + 1, cmd); - delete[] cmd; + strncpy(stateCmd + 1, cmd, cmdLen); + stateCmd[cmdLen + 1] = '\0'; + delete[] cmd; cmd = stateCmd; + + //Printf("%d %s\n", gametic, cmd); + return stateCmd; }