Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A possible memory corruption of m_used_name in Argument copy #226

Closed
lingerer opened this issue Oct 24, 2022 · 2 comments · Fixed by #304
Closed

A possible memory corruption of m_used_name in Argument copy #226

lingerer opened this issue Oct 24, 2022 · 2 comments · Fixed by #304

Comments

@lingerer
Copy link

lingerer commented Oct 24, 2022

A quick code

	argparse::ArgumentParser dyna;
	{
		argparse::ArgumentParser test("test", "1.0", argparse::default_arguments::none);
		test.add_argument("--v").default_value(1.1);
		test.parse_args(argc, argv);
		dyna = test;
	}

Arguments in m_positional_arguments of dyna will lost the m_used_name string_view value. It should be the local variable destruction make string_view failed. m_prefix_chars is the same.

@skrobinson
Copy link
Contributor

I initially agreed, but it looks like the m_used_name string_view is viewing one of the strings in Argument::m_names. Have you tried instrumenting your example (stdout or a debugger) to check the location of the string and view?

@lingerer
Copy link
Author

lingerer commented Oct 28, 2022

m_used_name is the same as m_argment_map's key.
I'm not familar with the implement of string_view, m_used_name address is xxxx2458 and m_names first address is xxxx2450
My suggestion is add a Argument copy construction to deal with it.

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

Successfully merging a pull request may close this issue.

2 participants