Make sure GetClipboardText's null returns are handled properly

This commit is contained in:
def 2015-08-26 16:40:59 +02:00
parent bd2b61f0e5
commit a1403ef457
3 changed files with 56 additions and 47 deletions

View file

@ -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))

View file

@ -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))

View file

@ -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))