Fix parsing of new types from C (#3068)

In the TypesWidget, right-click+Load New Types was opening the dialog
for editing an existing type instead of creating a new one. This would
either result in an error (for atomic types) or the old type being
deleted on success.
This commit is contained in:
Florian Märkl 2023-01-07 20:05:41 +01:00 committed by GitHub
parent ad82407c2c
commit 3d49c4b65a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -22,7 +22,6 @@ TypesInteractionDialog::TypesInteractionDialog(QWidget *parent, bool readOnly)
syntaxHighLighter = Config()->createSyntaxHighlighter(ui->plainTextEdit->document()); syntaxHighLighter = Config()->createSyntaxHighlighter(ui->plainTextEdit->document());
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui->plainTextEdit->setReadOnly(readOnly); ui->plainTextEdit->setReadOnly(readOnly);
this->typeName = "";
} }
TypesInteractionDialog::~TypesInteractionDialog() {} TypesInteractionDialog::~TypesInteractionDialog() {}
@ -64,10 +63,21 @@ void TypesInteractionDialog::done(int r)
{ {
if (r == QDialog::Accepted) { if (r == QDialog::Accepted) {
RzCoreLocked core(Core()); RzCoreLocked core(Core());
bool edited = rz_type_db_edit_base_type( bool success;
if (!typeName.isEmpty()) {
success = rz_type_db_edit_base_type(
core->analysis->typedb, this->typeName.toUtf8().constData(), core->analysis->typedb, this->typeName.toUtf8().constData(),
ui->plainTextEdit->toPlainText().toUtf8().constData()); ui->plainTextEdit->toPlainText().toUtf8().constData());
if (edited) { } else {
char *error_msg = NULL;
success = rz_type_parse_string_stateless(core->analysis->typedb->parser,
ui->plainTextEdit->toPlainText().toUtf8().constData(), &error_msg) == 0;
if (error_msg) {
RZ_LOG_ERROR("%s\n", error_msg);
rz_mem_free(error_msg);
}
}
if (success) {
emit newTypesLoaded(); emit newTypesLoaded();
QDialog::done(r); QDialog::done(r);
return; return;

View File

@ -293,7 +293,6 @@ void TypesWidget::on_actionLoad_New_Types_triggered()
TypesInteractionDialog dialog(this); TypesInteractionDialog dialog(this);
connect(&dialog, &TypesInteractionDialog::newTypesLoaded, this, &TypesWidget::refreshTypes); connect(&dialog, &TypesInteractionDialog::newTypesLoaded, this, &TypesWidget::refreshTypes);
dialog.setWindowTitle(tr("Load New Types")); dialog.setWindowTitle(tr("Load New Types"));
dialog.setTypeName(t.type);
dialog.exec(); dialog.exec();
} }