Opened 14 years ago

Closed 14 years ago

#8452 closed defect (fixed)

It should be checked !m_Text->GetFontProperties() in MythUITextEdit::MoveCursor(MoveDirection moveDir)

Reported by: sunny an <sunny71@…> Owned by: stuartm
Priority: minor Milestone: 0.24
Component: MythTV - User Interface Library Version: Unspecified
Severity: medium Keywords: MythUITextEdit
Cc: Ticket locked: no

Description

bool MythUITextEdit::MoveCursor(MoveDirection moveDir)
{
    if (!m_Text || !m_cursorImage)
        return false;
	
    QFontMetrics fm(m_Text->GetFontProperties()->face());

above code, m_Text->GetFontProperties?() could return invalid pointer.

void TestDialog::passwdChanged(void)
{
	QString input_passwd = m_passwd->GetText();
	if(input_passwd.length() == 4)
	{
		if(!input_passwd.compare(m_savedPasswd))
		{
			// if password is ok
			SendEvent(1, "passwd"));
			Close();
		}
		else
		{
			m_passwd->SetText(QString(""));
		}
	}
}

In the above sample code, passwdChanged(void) is connected to MythUITextEdit's valueChanged signal. If Close() is called, m_Font will be deleted in advance and then MythUITextEdit::MoveCursor?() called after that.

above code should be patched to bellow code.

bool MythUITextEdit::MoveCursor(MoveDirection moveDir)
{
    if (!m_Text || !m_cursorImage || !m_Text->GetFontProperties())
        return false;
	
    QFontMetrics fm(m_Text->GetFontProperties()->face());

Change History (5)

comment:1 Changed 14 years ago by robertm

Component: MythTV - GeneralMythTV - User Interface Library
Owner: changed from Isaac Richards to stuartm

comment:2 Changed 14 years ago by robertm

Status: newassigned

comment:3 Changed 14 years ago by stuartm

Status: assignedaccepted

I don't see how it's possible for the valueChanged() signal to be sent and received before MoveCursor?() is called, the signal is always sent as the last thing that we do. That's not just true in MythUITextEdit but all widgets.

I'll commit a check on GetFontProperties?() anyway since it does no harm.

comment:4 Changed 14 years ago by stuartm

Milestone: unknown0.24

comment:5 Changed 14 years ago by stuartm

Resolution: fixed
Status: acceptedclosed

(In [25716]) Add a null pointer check on m_Text->GetFontProperties?(), the explanation given in the ticket doesn't make sense, but the check itself is harmless. Closes #8452

Note: See TracTickets for help on using tickets.