8000 Use stol instead of sscanf · rmpowell77/docopt.cpp@2831ca6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2831ca6

Browse files
author
Matt Kline
committed
Use stol instead of sscanf
1 parent 4840f38 commit 2831ca6

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

docopt_value.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <vector>
1414
#include <functional> // std::hash
1515
#include <iosfwd>
16-
#include <cstdio> // sscanf
1716

181 8000 7
namespace docopt {
1918

@@ -261,12 +260,9 @@ namespace docopt {
261260
// Attempt to convert a string to a long
262261
if (kind == Kind::String) {
263262
// Doesn't guard against trailing characters,
264-
// but doing so (if desired) would be trivial.
265-
long ret;
266-
if (sscanf(variant.strValue.c_str(), "%ld", &ret) == 1) {
267-
return ret;
268-
}
269-
// else fall through
263+
// but doing so (if desired) would be trivial by checking pos.
264+
std::size_t pos;
265+
return stol(variant.strValue, &pos); // Throws if it can't convert
270266
}
271267
throwIfNotKind(Kind::Long);
272268
return variant.longValue;

0 commit comments

Comments
 (0)
0