From a1403ef4579f4b555b8a8783233c15d9ce63ca86 Mon Sep 17 00:00:00 2001 From: def Date: Wed, 26 Aug 2015 16:40:59 +0200 Subject: [PATCH] Make sure GetClipboardText's null returns are handled properly --- src/game/client/components/chat.cpp | 43 ++++++++++++++------------ src/game/client/components/console.cpp | 41 ++++++++++++------------ src/game/client/components/menus.cpp | 19 +++++++----- 3 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 0de697982..400ea9bfe 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -116,30 +116,33 @@ bool CChat::OnInput(IInput::CEvent Event) if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_V)) { - const char *text = Input()->GetClipboardText(); - // if the text has more than one line, we send all lines except the last one - // the last one is set as in the text field - char Line[256]; - int i, Begin = 0; - for(i = 0; i < str_length(text); i++) + const char *Text = Input()->GetClipboardText(); + if(Text) { - if(text[i] == '\n') + // if the text has more than one line, we send all lines except the last one + // the last one is set as in the text field + char Line[256]; + int i, Begin = 0; + for(i = 0; i < str_length(Text); i++) { - int max = i - Begin + 1; - if(max > (int)sizeof(Line)) - max = sizeof(Line); - str_copy(Line, text + Begin, max); - Begin = i+1; - SayChat(Line); - while(text[i] == '\n') i++; + if(Text[i] == '\n') + { + int max = i - Begin + 1; + if(max > (int)sizeof(Line)) + max = sizeof(Line); + str_copy(Line, Text + Begin, max); + Begin = i+1; + SayChat(Line); + while(Text[i] == '\n') i++; + } } + int max = i - Begin + 1; + if(max > (int)sizeof(Line)) + max = sizeof(Line); + str_copy(Line, Text + Begin, max); + Begin = i+1; + m_Input.Add(Line); } - int max = i - Begin + 1; - if(max > (int)sizeof(Line)) - max = sizeof(Line); - str_copy(Line, text + Begin, max); - Begin = i+1; - m_Input.Add(Line); } if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C)) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 50147bf07..abd13244c 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -95,31 +95,34 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) if(m_pGameConsole->Input()->KeyPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyDown(KEY_V)) { const char *Text = m_pGameConsole->Input()->GetClipboardText(); - char Line[256]; - int i, Begin = 0; - for(i = 0; i < str_length(Text); i++) + if(Text) { - if(Text[i] == '\n') + char Line[256]; + int i, Begin = 0; + for(i = 0; i < str_length(Text); i++) { - if(i == Begin) + if(Text[i] == '\n') { - Begin++; - continue; + if(i == Begin) + { + Begin++; + continue; + } + int max = i - Begin + 1; + if(max > (int)sizeof(Line)) + max = sizeof(Line); + str_copy(Line, Text + Begin, max); + Begin = i+1; + ExecuteLine(Line); } - int max = i - Begin + 1; - if(max > (int)sizeof(Line)) - max = sizeof(Line); - str_copy(Line, Text + Begin, max); - Begin = i+1; - ExecuteLine(Line); } + int max = i - Begin + 1; + if(max > (int)sizeof(Line)) + max = sizeof(Line); + str_copy(Line, Text + Begin, max); + Begin = i+1; + m_Input.Add(Line); } - int max = i - Begin + 1; - if(max > (int)sizeof(Line)) - max = sizeof(Line); - str_copy(Line, Text + Begin, max); - Begin = i+1; - m_Input.Add(Line); } if(m_pGameConsole->Input()->KeyPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyDown(KEY_C)) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 9b0c7ab08..fa2d9c443 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -241,16 +241,19 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_V)) { const char *Text = Input()->GetClipboardText(); - int CharsLeft = StrSize - str_length(pStr); - int Offset = str_length(pStr); - for(int i = 0; i < str_length(Text) && i <= CharsLeft; i++) + if(Text) { - if(Text[i] == '\n') - pStr[i + Offset] = ' '; - else - pStr[i + Offset] = Text[i]; + int CharsLeft = StrSize - str_length(pStr); + int Offset = str_length(pStr); + for(int i = 0; i < str_length(Text) && i <= CharsLeft; i++) + { + if(Text[i] == '\n') + pStr[i + Offset] = ' '; + else + pStr[i + Offset] = Text[i]; + } + s_AtIndex = str_length(pStr); } - s_AtIndex = str_length(pStr); } if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C))