Skip to content
Permalink
Browse files

+ use QString's vsprintf to avoid to truncate the output string

  • Loading branch information...
wwmayer committed Jun 4, 2016
1 parent 108fe75 commit 3c269f4ccd5680867246c63ea415ccf327182e96
Showing with 25 additions and 42 deletions.
  1. +10 −19 src/Gui/Application.cpp
  2. +15 −23 src/Gui/Command.cpp
@@ -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)
@@ -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

0 comments on commit 3c269f4

Please sign in to comment.
You can’t perform that action at this time.