summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/scripting/mozjs/numberlong.cpp6
-rw-r--r--src/mongo/util/text.cpp21
-rw-r--r--src/mongo/util/text.h4
3 files changed, 5 insertions, 26 deletions
diff --git a/src/mongo/scripting/mozjs/numberlong.cpp b/src/mongo/scripting/mozjs/numberlong.cpp
index d211ed44081..f03a0631805 100644
--- a/src/mongo/scripting/mozjs/numberlong.cpp
+++ b/src/mongo/scripting/mozjs/numberlong.cpp
@@ -33,6 +33,7 @@
#include <boost/optional.hpp>
#include <js/Conversions.h>
+#include "mongo/base/parse_number.h"
#include "mongo/scripting/mozjs/implscope.h"
#include "mongo/scripting/mozjs/objectwrapper.h"
#include "mongo/scripting/mozjs/valuereader.h"
@@ -170,7 +171,10 @@ void NumberLongInfo::construct(JSContext* cx, JS::CallArgs args) {
// For string values we call strtoll because we expect non-number string
// values to fail rather than return 0 (which is the behavior of ToInt64).
std::string str = ValueWriter(cx, arg).toString();
- numLong = parseLL(str.c_str());
+
+ // Call parseNumberFromStringWithBase() function to convert string to a number
+ Status status = parseNumberFromStringWithBase(str, 10, &numLong);
+ uassert(ErrorCodes::BadValue, "could not convert string to long long", status.isOK());
} else {
numLong = ValueWriter(cx, arg).toInt64();
}
diff --git a/src/mongo/util/text.cpp b/src/mongo/util/text.cpp
index f8282cfdccb..042b399adb1 100644
--- a/src/mongo/util/text.cpp
+++ b/src/mongo/util/text.cpp
@@ -150,27 +150,6 @@ bool isValidUTF8(const char* s) {
return true;
}
-long long parseLL(const char* n) {
- long long ret;
- uassert(13307, "cannot convert empty string to long long", *n != 0);
-#if !defined(_WIN32)
- char* endPtr = 0;
- errno = 0;
- ret = strtoll(n, &endPtr, 10);
- uassert(13305, "could not convert string to long long", *endPtr == 0 && errno == 0);
-#else
- size_t endLen = 0;
- try {
- ret = stoll(n, &endLen, 10);
- } catch (...) {
- endLen = 0;
- }
- uassert(13306, "could not convert string to long long", endLen != 0 && n[endLen] == 0);
-#endif // !defined(_WIN32)
- return ret;
-}
-
-
#if defined(_WIN32)
std::string toUtf8String(const std::wstring& wide) {
diff --git a/src/mongo/util/text.h b/src/mongo/util/text.h
index 08c87742bad..5565309b081 100644
--- a/src/mongo/util/text.h
+++ b/src/mongo/util/text.h
@@ -73,10 +73,6 @@ private:
bool isValidUTF8(const char* s);
bool isValidUTF8(const std::string& s);
-// expect that n contains a base ten number and nothing else after it
-// NOTE win version hasn't been tested directly
-long long parseLL(const char* n);
-
#if defined(_WIN32)
std::string toUtf8String(const std::wstring& wide);