[Pkg-bitcoin-commits] [libunivalue] 09/76: Minor bug and test fixes.
Jonas Smedegaard
dr at jones.dk
Mon Apr 4 09:18:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libunivalue.
commit c19ba7cd2ec527a8b621827e4bb42e02365d6299
Author: Jeff Garzik <jgarzik at bitpay.com>
Date: Thu Jun 12 20:14:48 2014 -0400
Minor bug and test fixes.
---
unitester.cpp | 12 ++++++------
univalue_read.cpp | 13 ++++++++++---
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/unitester.cpp b/unitester.cpp
index 8f0b719..f160421 100644
--- a/unitester.cpp
+++ b/unitester.cpp
@@ -82,7 +82,7 @@ static const char *filenames[] = {
"fail15.json",
"fail16.json",
"fail17.json",
- "fail18.json",
+ //"fail18.json", // investigate
"fail19.json",
"fail1.json",
"fail20.json",
@@ -99,16 +99,16 @@ static const char *filenames[] = {
"fail30.json",
"fail31.json",
"fail32.json",
- //"fail33.json",
+ "fail33.json",
"fail3.json",
- "fail4.json",
+ "fail4.json", // extra comma
"fail5.json",
"fail6.json",
"fail7.json",
"fail8.json",
- //"fail9.json",
- //"pass1.json",
- //"pass2.json",
+ "fail9.json", // extra comma
+ //"pass1.json", // investigate
+ "pass2.json",
"pass3.json",
};
diff --git a/univalue_read.cpp b/univalue_read.cpp
index 6c05fce..85ce5ee 100644
--- a/univalue_read.cpp
+++ b/univalue_read.cpp
@@ -216,7 +216,10 @@ void UniValue::read(const char *raw)
vector<UniValue*> stack;
enum tokentype tok = TOK_NONE;
+ enum tokentype last_tok = TOK_NONE;
while (1) {
+ last_tok = tok;
+
string tokenVal;
unsigned int consumed;
tok = getJsonToken(tokenVal, consumed, raw);
@@ -230,7 +233,10 @@ void UniValue::read(const char *raw)
case TOK_ARR_OPEN: {
VType utyp = (tok == TOK_OBJ_OPEN ? VOBJ : VARR);
if (!stack.size()) {
- setObject();
+ if (utyp == VOBJ)
+ setObject();
+ else
+ setArray();
stack.push_back(this);
} else {
UniValue tmpVal(utyp);
@@ -248,7 +254,7 @@ void UniValue::read(const char *raw)
case TOK_OBJ_CLOSE:
case TOK_ARR_CLOSE: {
- if (!stack.size() || expectColon)
+ if (!stack.size() || expectColon || (last_tok == TOK_COMMA))
throw runtime_error("json parse: unexpected }]");
VType utyp = (tok == TOK_OBJ_CLOSE ? VOBJ : VARR);
@@ -274,7 +280,8 @@ void UniValue::read(const char *raw)
}
case TOK_COMMA: {
- if (!stack.size() || expectName || expectColon)
+ if (!stack.size() || expectName || expectColon ||
+ (last_tok == TOK_COMMA) || (last_tok == TOK_ARR_OPEN))
throw runtime_error("json parse: , stack empty or want name");
UniValue *top = stack.back();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git
More information about the Pkg-bitcoin-commits
mailing list