# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-10-10 14:48:42 # Node ID b1ac644087e593eda06b3687989dde9252964bdd # Parent 9add38e39c0adb927630677ee0196bac884e27ae when switching from hex to ascii, patch hex string in case of missing nibble diff --git a/commandedit.cpp b/commandedit.cpp --- a/commandedit.cpp +++ b/commandedit.cpp @@ -19,6 +19,8 @@ #include +#include + #include "commandedit.h" class HexCommandValidator : public QRegExpValidator @@ -76,7 +78,16 @@ void CommandEdit::setMode(bool ascii) if (ascii) { setValidator(asciiValidator); - setText(QByteArray::fromHex(text().remove(" ").toLatin1())); + + auto hexText = text().remove(" "); + // try patching HEX string in case of missing nibble so that + // input doesn't turn into gibberish + if (hexText.size() % 2 == 1) + { + hexText.replace(hexText.size()-1, 1, "3F"); // 0x3F = '?' + qWarning() << "Broken byte in hex command is replaced. Check your command!"; + } + setText(QByteArray::fromHex(hexText.toLatin1())); } else {