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

This commit is contained in:
wmayer 2016-06-04 10:37:08 +02:00
parent 108fe75464
commit 3c269f4ccd
2 changed files with 25 additions and 42 deletions

View File

@ -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);
d->macroMngr->addLine(MacroManager::Gui, format.constData());
try {
Base::Interpreter().runString(format);
}
catch (...) {
// free memory to avoid a leak if an exception occurred
free (format);
throw;
}
free (format);
Base::Interpreter().runString(format.constData());
}
bool Application::runPythonCode(const char* cmd, bool gui, bool pyexc)

View File

@ -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