Browse files

Correct issue where too narrow a console can break help output

If the terminal width used to display the help output is narrower than
the longest defined argument, the command line parser will attempt to
wrap the help text at a negative length, and will eventually OOM.  This
makes sure that the wrap function does not allow that, and tries to
behave a bit more intelligently during help output.

Fixes #11688
  • Loading branch information...
wagnerrp committed Jul 17, 2013
1 parent 995db9d commit 1ebf70131c868160b3a6225e99f11c0c5a900bff
Showing with 15 additions and 0 deletions.
  1. +11 −0 mythtv/libs/libmythbase/mythcommandlineparser.cpp
  2. +4 −0 mythtv/libs/libmythbase/mythmiscutil.cpp
@@ -259,6 +259,17 @@ QString CommandLineArg::GetHelpString(int off, QString group, bool force) const
QString helpstr;
QTextStream msg(&helpstr, QIODevice::WriteOnly);
int termwidth = GetTermWidth();
if (termwidth < off)
if (off > 70)
// developer has configured some absurdly long command line
// arguments, but we still need to do something
termwidth = off+40;
// user is running uselessly narrow console, use a sane console
// width instead
termwidth = 79;
if (m_help.isEmpty() && !force)
// only print if there is a short help to print
@@ -943,6 +943,10 @@ void wrapList(QStringList &list, int width)
int i;
// if this is triggered, something has gone seriously wrong
// the result won't really be usable, but at least it won't crash
width = max(width, 5);
for(i = 0; i < list.size(); i++)
QString string =;

0 comments on commit 1ebf701

Please sign in to comment.