Skip to content

common/strtol: fix strict_strtoll() so it accepts hex starting with 0x#21521

Merged
tchaikov merged 1 commit intoceph:masterfrom
tchaikov:wip-stoll
Apr 21, 2018
Merged

common/strtol: fix strict_strtoll() so it accepts hex starting with 0x#21521
tchaikov merged 1 commit intoceph:masterfrom
tchaikov:wip-stoll

Conversation

@tchaikov
Copy link
Contributor

  • simplify the error handling of strtoll().
  • only instantiate ostringstream when handling errors.

Signed-off-by: Kefu Chai kchai@redhat.com

Copy link
Contributor

@jan--f jan--f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @tchaikov looks good. It would be nice to use std::from_chars once its available in the stdlib.

*err = errStr.str();
if (endptr == str.data() || endptr != str.data() + str.size()) {
*err = (std::string("Expected option value to be integer, got '") +
std::string(str.data(), str.size()) + "'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string(str) also works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ukernel sure, updated and repushed

@tchaikov tchaikov force-pushed the wip-stoll branch 2 times, most recently from e763ac3 to 8359d16 Compare April 19, 2018 14:37
- simplify the error handling of strtoll().
- only instantiate ostringstream when handling errors.

Signed-off-by: Kefu Chai <kchai@redhat.com>
@tchaikov tchaikov merged commit 717b941 into ceph:master Apr 21, 2018
@tchaikov tchaikov deleted the wip-stoll branch April 21, 2018 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants