diff --git a/build/VS2010/flatc.vcxproj b/build/VS2010/flatc.vcxproj
index 84200a56c..d180dd9df 100755
--- a/build/VS2010/flatc.vcxproj
+++ b/build/VS2010/flatc.vcxproj
@@ -271,6 +271,7 @@
Level4
+
diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h
index 67f75d525..8e5d09908 100644
--- a/include/flatbuffers/util.h
+++ b/include/flatbuffers/util.h
@@ -90,8 +90,17 @@ inline std::string IntToStringHex(int i, int xdigits) {
return ss.str();
}
-// Portable implementation of strtoull().
+// Portable implementation of strtoll().
inline int64_t StringToInt(const char *str, int base = 10) {
+ #ifdef _MSC_VER
+ return _strtoi64(str, nullptr, base);
+ #else
+ return strtoll(str, nullptr, base);
+ #endif
+}
+
+// Portable implementation of strtoull().
+inline int64_t StringToUInt(const char *str, int base = 10) {
#ifdef _MSC_VER
return _strtoui64(str, nullptr, base);
#else
diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp
index 7db80e8d7..84ee6ae8c 100644
--- a/src/idl_gen_js.cpp
+++ b/src/idl_gen_js.cpp
@@ -101,7 +101,7 @@ static void GenDocComment(const std::vector &dc,
}
if (indent) code += indent;
std::string::size_type start = 0;
- while (true) {
+ for (;;) {
auto end = extra_lines.find('\n', start);
if (end != std::string::npos) {
code += " * " + extra_lines.substr(start, end - start) + "\n";
@@ -207,7 +207,7 @@ static std::string GenDefaultValue(const Value &value) {
case BASE_TYPE_LONG:
case BASE_TYPE_ULONG:
if (value.constant != "0") {
- int64_t constant = std::atoll(value.constant.c_str());
+ int64_t constant = StringToInt(value.constant.c_str());
return "new flatbuffers.Long(" + NumToString((int32_t)constant) +
", " + NumToString((int32_t)(constant >> 32)) + ")";
}
@@ -218,13 +218,8 @@ static std::string GenDefaultValue(const Value &value) {
}
}
-enum struct InOut {
- IN,
- OUT,
-};
-
-static std::string GenTypeName(const Type &type, InOut inOut) {
- if (inOut == InOut::OUT) {
+static std::string GenTypeName(const Type &type, bool input) {
+ if (!input) {
if (type.base_type == BASE_TYPE_STRING) {
return "string|Uint8Array";
}
@@ -289,7 +284,7 @@ static void GenStructArgs(const StructDef &struct_def,
GenStructArgs(*field.value.type.struct_def, annotations, arguments,
nameprefix + field.name + "_");
} else {
- *annotations += "@param {" + GenTypeName(field.value.type, InOut::IN);
+ *annotations += "@param {" + GenTypeName(field.value.type, true);
*annotations += "} " + nameprefix + field.name + "\n";
*arguments += ", " + nameprefix + field.name;
}
@@ -406,7 +401,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
GenDocComment(field.doc_comment, code_ptr,
std::string(field.value.type.base_type == BASE_TYPE_STRING ?
"@param {flatbuffers.Encoding=} optionalEncoding\n" : "") +
- "@returns {" + GenTypeName(field.value.type, InOut::OUT) + "}");
+ "@returns {" + GenTypeName(field.value.type, false) + "}");
code += object_name + ".prototype." + MakeCamel(field.name, false);
code += " = function(";
if (field.value.type.base_type == BASE_TYPE_STRING) {
@@ -452,7 +447,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
case BASE_TYPE_VECTOR: {
auto vectortype = field.value.type.VectorType();
- auto vectortypename = GenTypeName(vectortype, InOut::OUT);
+ auto vectortypename = GenTypeName(vectortype, false);
auto inline_size = InlineSize(vectortype);
auto index = "this.bb.__vector(this.bb_pos + offset) + index" +
MaybeScale(inline_size);
@@ -559,7 +554,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
// Generate the field insertion method
GenDocComment(code_ptr,
"@param {flatbuffers.Builder} builder\n"
- "@param {" + GenTypeName(field.value.type, InOut::IN) + "} " +
+ "@param {" + GenTypeName(field.value.type, true) + "} " +
argname);
code += object_name + ".add" + MakeCamel(field.name);
code += " = function(builder, " + argname + ") {\n";
@@ -588,7 +583,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
if (!IsStruct(vector_type)) {
GenDocComment(code_ptr,
"@param {flatbuffers.Builder} builder\n"
- "@param {Array.<" + GenTypeName(vector_type, InOut::IN) +
+ "@param {Array.<" + GenTypeName(vector_type, true) +
">} data\n"
"@returns {flatbuffers.Offset}");
code += object_name + ".create" + MakeCamel(field.name);
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index 6b3631d39..1a55bace2 100644
--- a/src/idl_parser.cpp
+++ b/src/idl_parser.cpp
@@ -159,7 +159,7 @@ int64_t Parser::ParseHexNum(int nibbles) {
Error("escape code must be followed by " + NumToString(nibbles) +
" hex digits");
std::string target(cursor_, cursor_ + nibbles);
- auto val = StringToInt(target.c_str(), 16);
+ auto val = StringToUInt(target.c_str(), 16);
cursor_ += nibbles;
return val;
}
@@ -288,7 +288,7 @@ void Parser::Next() {
cursor_++;
while (isxdigit(static_cast(*cursor_))) cursor_++;
attribute_.append(start + 2, cursor_);
- attribute_ = NumToString(StringToInt(attribute_.c_str(), 16));
+ attribute_ = NumToString(StringToUInt(attribute_.c_str(), 16));
token_ = kTokenIntegerConstant;
return;
}