Skip to content

Commit

Permalink
Correct issue where too narrow a console can break help output
Browse files Browse the repository at this point in the history
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 1ebf701
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mythtv/libs/libmythbase/mythcommandlineparser.cpp
Expand Up @@ -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;
else
// 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
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythbase/mythmiscutil.cpp
Expand Up @@ -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 = list.at(i);
Expand Down

0 comments on commit 1ebf701

Please sign in to comment.