Modify

Opened 11 years ago

Closed 8 years ago

Last modified 8 years ago

#689 closed Bugs (fixed)

[program_options] Endless loop with long default arguments

Reported by: ensc Owned by: Vladimir Prus
Milestone: Boost 1.42.0 Component: program_options
Version: None Severity: Problem
Keywords: Cc: s.ochsenknecht@…

Description

when using a po::value with a representation of the default value
having a certain length, 'std::cout << opts' will stuck in an endless
loop.

E.g.

-----
#include <boost/program_options.hpp>
#include <string>
#include <iostream>

namespace po = boost::program_options;

int main(int argc, char *argv[])
{
  po::options_description		opts;
  opts.add_options()
    ("cfgfile,c",
     po::value<std::string>()->default_value("/usr/local/etc/myprogramXXXXXXXXX/configuration.conf"),
     "the configfile");

  std::cout << opts;
}
-----

| $ rpm -q boost
| boost-1.33.1-5
| 
| $ g++ foo.c  -lboost_program_options
| $ strace ./a.out
| ...
| write(1, "  -c [ --cfgfile ] arg (=/usr/lo"..., 80  -c [ --cfgfile ] arg (=/usr/local/etc/myprogramXXXXXXXXX/configuration.conf) 
| ) = 80
| write(1, "                                "..., 80                                                                               
| ) = 80
| write(1, "                                "..., 80                                                                               
| ) = 80
| ...



Removing one 'X' will result in an ugly

|   -c [ --cfgfile ] arg (=/usr/local/etc/myprogramXXXXXXXX/configuration.conf) t
|                                                                               h
|                                                                               e
|                                                                               c
|                                                                               o
|                                                                               n
|                                                                               f
|                                                                               i
|                                                                               g
|                                                                               f
|                                                                               i
|                                                                               l
|                                                                               e

output.


It would be nice, when:

- the default value could be moved into the description column
- the description would begin on a new line and an earlier column
  (e.g. 30-40) when option name/default-value are too long (> 30-40
  chars)

Attachments (1)

patch1.diff (2.6 KB) - added by s.ochsenknecht@… 8 years ago.
patch

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by nobody

Logged In: NO 

Hit this one as well.

comment:2 Changed 10 years ago by Daryle Walker

Component: Noneprogram_options
Severity: Problem

Changed 8 years ago by s.ochsenknecht@…

Attachment: patch1.diff added

patch

comment:3 Changed 8 years ago by s.ochsenknecht@…

I added a patch which solves this ticket.

When printing out all program options it will go to a new line and print out the description on the next line if the first part is too long. The output from the test case will look like the following with the patch:

  -c [ --cfgfile ] arg (=/usr/local/etc/myprogramXXXXXXXX/configuration.conf)
                                        the configfile
  -f [ --fritz ] arg (=/other/file)     the output file

Is it useful? Any comments?

I'm not a boost maintainer, so I'll better to keep the status of this ticket ... :-)

comment:4 Changed 8 years ago by Sascha Ochsenknecht <s.ochsenknecht@…>

Cc: s.ochsenknecht@… added

comment:5 Changed 8 years ago by Vladimir Prus

Resolution: Nonefixed
Status: assignedclosed

(In [57271]) Put description to next line if we'd overflow otherwise. Fixes #689.

Patch from Sascha Ochsenknecht.

comment:6 Changed 8 years ago by Vladimir Prus

Sascha, I have applied your patch. I have also added a testcase. Note that your patch had a few formatting changes, which I've left out in order not to mix semantic and formatting changes in one commit.

Thanks!

comment:7 Changed 8 years ago by Sascha Ochsenknecht

Milestone: Boost 1.42.0

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Vladimir Prus.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.