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 all commits
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
29 changes: 25 additions & 4 deletions src/gui/plugins/spawn/Spawn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ namespace gz::sim

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

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

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

/////////////////////////////////////////////////
std::string SpawnPrivate::AddNewLine(const 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.append("-\n");
}
out.push_back(_str[i]);
}
return out;
}

/////////////////////////////////////////////////
void SpawnPrivate::HandlePlacement()
{
Expand Down Expand Up @@ -581,10 +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, FBX, GLTF, 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;
}

Expand Down