From 12187cb8700f0742951eb7834fa075054e676d56 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Sat, 1 Oct 2016 16:41:53 +0300 Subject: [PATCH] Fix uninitialized value memory error While profiling using Valgrind, two uninitialized value errors popped up, because the dataSource iVar was used in the if check from the editTextChanged function before initializing it. This commit moves the dataSource initializations before any other calls. --- src/EditDialog.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 24943b8c61..d462b51a4d 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -94,31 +94,34 @@ void EditDialog::loadData(const QByteArray& data) case Null: switch (editMode) { case TextEditor: + // The text widget buffer is now the main data source + dataSource = TextBuffer; + // Empty the text editor contents, then enable text editing ui->editorText->clear(); ui->editorText->setEnabled(true); - // The text widget buffer is now the main data source - dataSource = TextBuffer; break; case HexEditor: + // The hex widget buffer is now the main data source + dataSource = HexBuffer; + // Load the Null into the hex editor hexEdit->setData(data); - // The hex widget buffer is now the main data source - dataSource = HexBuffer; break; case ImageViewer: + // The hex widget buffer is now the main data source + dataSource = HexBuffer; + // Clear any image from the image viewing widget ui->editorImage->setPixmap(QPixmap(0,0)); // Load the Null into the hex editor hexEdit->setData(data); - // The hex widget buffer is now the main data source - dataSource = HexBuffer; break; } break; @@ -126,6 +129,9 @@ void EditDialog::loadData(const QByteArray& data) case Text: switch (editMode) { case TextEditor: + // The text widget buffer is now the main data source + dataSource = TextBuffer; + // Load the text into the text editor textData = QString::fromUtf8(data.constData(), data.size()); ui->editorText->setPlainText(textData); @@ -136,20 +142,21 @@ void EditDialog::loadData(const QByteArray& data) // Select all of the text by default ui->editorText->selectAll(); - // The text widget buffer is now the main data source - dataSource = TextBuffer; - break; case HexEditor: + // The hex widget buffer is now the main data source + dataSource = HexBuffer; + // Load the text into the hex editor hexEdit->setData(data); - // The hex widget buffer is now the main data source - dataSource = HexBuffer; break; case ImageViewer: + // The text widget buffer is now the main data source + dataSource = TextBuffer; + // Clear any image from the image viewing widget ui->editorImage->setPixmap(QPixmap(0,0)); @@ -163,9 +170,6 @@ void EditDialog::loadData(const QByteArray& data) // Select all of the text by default ui->editorText->selectAll(); - // The text widget buffer is now the main data source - dataSource = TextBuffer; - break; } break; @@ -200,15 +204,15 @@ void EditDialog::loadData(const QByteArray& data) break; default: + // The hex widget buffer is now the main data source + dataSource = HexBuffer; + // The data seems to be general binary data, which is always loaded // into the hex widget (the only safe place for it) // Load the data into the hex editor hexEdit->setData(data); - // The hex widget buffer is now the main data source - dataSource = HexBuffer; - switch (editMode) { case TextEditor: // Disable text editing, and use a warning message as the contents