Skip to content
Permalink
Browse files

Fix Empty Keyboard String Crashes (#1744)

Check if the keyboard_string is empty before attempting to pop a character off the end when backspace is pressed. This fixes crashes in compile mode executables reported by Darkstar. Also deleted old redundant declarations that were lingering around.
  • Loading branch information...
RobertBColton committed Jun 12, 2019
1 parent 9f59be7 commit 1ab91aefefe8fd7019ffbab876448b7bf65463b0
@@ -23,9 +23,8 @@ using std::map;
#include <windows.h>
//#include <winuser.h> // includes windows.h

#include "../General/PFwindow.h"

#include "Platforms/General/PFmain.h" // For those damn vk_ constants.
#include "Platforms/General/PFmain.h" // for keyboard_string
#include "Platforms/General/PFwindow.h" // For those damn vk_ constants.
#include "Universal_System/Instances/instance_system.h"
#include "Universal_System/Instances/instance.h"

@@ -36,10 +35,6 @@ using std::map;
#endif

namespace enigma_user {
extern int keyboard_key;
extern int keyboard_lastkey;
extern string keyboard_lastchar;
extern string keyboard_string;
void draw_clear(int col);
void screen_set_viewport(gs_scalar x, gs_scalar y, gs_scalar width, gs_scalar height);
}
@@ -168,7 +163,7 @@ namespace enigma
case WM_CHAR:
keyboard_lastchar = string(1,wParam);
if (keyboard_lastkey == enigma_user::vk_backspace) {
keyboard_string = keyboard_string.substr(0, keyboard_string.length() - 1);
if (!keyboard_string.empty()) keyboard_string.pop_back();
} else {
keyboard_string += keyboard_lastchar;
}
@@ -71,8 +71,7 @@ int handleEvents() {
if (len > 0) {
enigma_user::keyboard_lastchar = string(1, str[0]);
if (actualKey == enigma_user::vk_backspace) {
enigma_user::keyboard_string =
enigma_user::keyboard_string.substr(0, enigma_user::keyboard_string.length() - 1);
if (!enigma_user::keyboard_string.empty()) enigma_user::keyboard_string.pop_back();
} else {
enigma_user::keyboard_string += enigma_user::keyboard_lastchar;
}

0 comments on commit 1ab91ae

Please sign in to comment.
You can’t perform that action at this time.