Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Parser::operator<< fails for long help strings #41

Closed
stefansullivan opened this issue Nov 7, 2017 · 5 comments
Closed

Parser::operator<< fails for long help strings #41

stefansullivan opened this issue Nov 7, 2017 · 5 comments
Labels

Comments

@stefansullivan
Copy link

I get a std::bad_alloc for help strings that are too wide for my console when trying to do std::cerr << cli << std::endl;

The problem comes from this line of code:

                auto row =
                        TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) +
                        TextFlow::Spacer(4) +
                        TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth );

where optWidth is not bounded to be less than consoleWidth - 7

@stefansullivan
Copy link
Author

Also, note that

        auto width( size_t newWidth ) -> Column& {
            assert( newWidth > 0 );
            m_width = newWidth;
            return *this;
        }

in clara_textflow.hpp won't ever trigger the assert, because size_t is an unsigned type, and its invocations will wrap-around if they aren't called correctly

@philsquared
Copy link
Collaborator

Hi,
Sorry for the delay in getting to this.
I've pushed a fix for it, along with some basic tests (I plan to do more, property-based style, tests of this sort of thing).
Could you check if it works for you now?

Regarding that assert - yeah that looks like a hold over from newWidth being a signed type. Not harmful, but I'll remove it - thanks.

@philsquared
Copy link
Collaborator

HI @stefansullivan are you able to confirm (or otherwise) that this is fixed for you?
As of yesterday it should be part of the v1.1.0 release.

@stefansullivan
Copy link
Author

Thanks for the update @philsquared. I'll update soon and let you know.

@stefansullivan
Copy link
Author

Sorry for the slow response. Just finally got around to testing newer version. Looks fine. Thanks for the fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants