Skip to content

Commit

Permalink
+ use QString's vsprintf to avoid to truncate the output string
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jun 4, 2016
1 parent 108fe75 commit 3c269f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 42 deletions.
29 changes: 10 additions & 19 deletions src/Gui/Application.cpp
Expand Up @@ -1357,29 +1357,20 @@ CommandManager &Application::commandManager(void)

void Application::runCommand(bool bForce, const char* sCmd,...)
{
// temp buffer
size_t format_len = std::strlen(sCmd)+4024;
char* format = (char*) malloc(format_len);
va_list namelessVars;
va_start(namelessVars, sCmd); // Get the "..." vars
vsnprintf(format, format_len, sCmd, namelessVars);
va_end(namelessVars);
va_list ap;
va_start(ap, sCmd);
QString s;
const QString cmd = s.vsprintf(sCmd, ap);
va_end(ap);

QByteArray format = cmd.toLatin1();

if (bForce)
d->macroMngr->addLine(MacroManager::App,format);
d->macroMngr->addLine(MacroManager::App, format.constData());
else
d->macroMngr->addLine(MacroManager::Gui,format);

try {
Base::Interpreter().runString(format);
}
catch (...) {
// free memory to avoid a leak if an exception occurred
free (format);
throw;
}
d->macroMngr->addLine(MacroManager::Gui, format.constData());

free (format);
Base::Interpreter().runString(format.constData());
}

bool Application::runPythonCode(const char* cmd, bool gui, bool pyexc)
Expand Down
38 changes: 15 additions & 23 deletions src/Gui/Command.cpp
Expand Up @@ -431,34 +431,26 @@ void Command::blockCommand(bool block)
}

/// Run a App level Action
void Command::doCommand(DoCmd_Type eType,const char* sCmd,...)
void Command::doCommand(DoCmd_Type eType, const char* sCmd, ...)
{
// temp buffer
size_t format_len = std::strlen(sCmd)+4024;
char* format = (char*) malloc(format_len);
va_list namelessVars;
va_start(namelessVars, sCmd); // Get the "..." vars
vsnprintf(format, format_len, sCmd, namelessVars);
va_end(namelessVars);
va_list ap;
va_start(ap, sCmd);
QString s;
const QString cmd = s.vsprintf(sCmd, ap);
va_end(ap);

if (eType == Gui)
Gui::Application::Instance->macroManager()->addLine(MacroManager::Gui,format);
else
Gui::Application::Instance->macroManager()->addLine(MacroManager::App,format);

try {
Base::Interpreter().runString(format);
}
catch (...) {
// free memory to avoid a leak if an exception occurred
free (format);
throw;
}
QByteArray format = cmd.toLatin1();

#ifdef FC_LOGUSERACTION
Base::Console().Log("CmdC: %s\n",format);
Base::Console().Log("CmdC: %s\n", format.constData());
#endif
free (format);

if (eType == Gui)
Gui::Application::Instance->macroManager()->addLine(MacroManager::Gui, format.constData());
else
Gui::Application::Instance->macroManager()->addLine(MacroManager::App, format.constData());

Base::Interpreter().runString(format.constData());
}

/// Run a App level Action
Expand Down

0 comments on commit 3c269f4

Please sign in to comment.