Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow if dropStr is large #1654

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Divides the dropStr if its too large
Large mesh file names creates ugly error message
by overflow. This commit fixes this.

Signed-off-by: Onur Berk Tore <otore19@ku.edu.tr>
Onur Berk Tore committed Aug 17, 2022
commit 06d9fb38a50926a8d3007ed6da3e1ba038e5a385
28 changes: 25 additions & 3 deletions src/gui/plugins/spawn/Spawn.cc
Original file line number Diff line number Diff line change
@@ -146,6 +146,9 @@ namespace gz::sim

/// \brief Text for popup error message
public: QString errorPopupText;

/// \brief Adds new line after each new nChar.
public: std::string AddNewLine(std::string &str, int nChar);
};
}

@@ -188,6 +191,22 @@ void Spawn::LoadConfig(const tinyxml2::XMLElement *)
<gz::gui::MainWindow *>()->installEventFilter(this);
}

/////////////////////////////////////////////////
std::string SpawnPrivate::AddNewLine(std::string &str, int nChar)
{
std::string out;
out.reserve(str.size() + str.size() / nChar);
for(std::string::size_type i = 0; i < str.size(); i++) {
if (!(i % nChar) && i) {
out.push_back('-');
out.push_back('\n');
}
out.push_back(str[i]);
}
return out;
}


/////////////////////////////////////////////////
void SpawnPrivate::HandlePlacement()
{
@@ -581,9 +600,12 @@ void Spawn::OnDropped(const gz::gui::events::DropOnScene *_event)

if (!common::MeshManager::Instance()->IsValidFilename(dropStr))
{
QString errTxt = QString::fromStdString("Invalid URI: " + dropStr +
"\nOnly Fuel URLs or mesh file types DAE, OBJ, and STL are supported.");
this->SetErrorPopupText(errTxt);
std::string fixedDropStr = this->dataPtr->AddNewLine(dropStr, 55);
std::string errTxt = "Invalid URI: " + fixedDropStr +
"\nOnly Fuel URLs or mesh file types DAE, FBX, GLTF, OBJ, and STL\n"
"are supported.";
QString QErrTxt = QString::fromStdString(errTxt);
this->SetErrorPopupText(QErrTxt);
return;
}