From 39c185ae67071bb7b32d01ec61eeab568be7f1bc Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 14 Jul 2014 14:50:43 +0200 Subject: [PATCH] Fixed bug in JsonObjectBase::getBoolFromToken() --- JsonParser/JsonObjectBase.cpp | 56 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/JsonParser/JsonObjectBase.cpp b/JsonParser/JsonObjectBase.cpp index 2a8092b3..c86ff069 100644 --- a/JsonParser/JsonObjectBase.cpp +++ b/JsonParser/JsonObjectBase.cpp @@ -10,58 +10,58 @@ using namespace ArduinoJson::Parser; int JsonObjectBase::getNestedTokenCount(jsmntok_t* token) { - int end = token->end; - int count = 0; + int end = token->end; + int count = 0; - token++; + token++; - while (token->start < end) - { - token++; - count++; - } + while (token->start < end) + { + token++; + count++; + } - return count; + return count; } bool JsonObjectBase::getBoolFromToken(jsmntok_t* token) { - if (token->type != JSMN_PRIMITIVE) return 0; + if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; - // "true" - if (json[token->start] == 't') return true; + // "true" + if (json[token->start] == 't') return true; - // "false" - if (json[token->start] == 'f') return false; + // "false" + if (json[token->start] == 'f') return false; - // "null" - if (json[token->start] == 'n') return false; - - // number - return strtol(json + token->start, 0, 0) != 0; + // "null" + if (json[token->start] == 'n') return false; + + // number + return strtol(json + token->start, 0, 0) != 0; } double JsonObjectBase::getDoubleFromToken(jsmntok_t* token) { - if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; + if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; - return strtod(json + token->start, 0); + return strtod(json + token->start, 0); } long JsonObjectBase::getLongFromToken(jsmntok_t* token) { - if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; + if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; - return strtol(json + token->start, 0, 0); + return strtol(json + token->start, 0, 0); } char* JsonObjectBase::getStringFromToken(jsmntok_t* token) { - if (token == 0 || token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING) - return 0; + if (token == 0 || token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING) + return 0; - // add null terminator to the string - json[token->end] = 0; + // add null terminator to the string + json[token->end] = 0; - return json + token->start; + return json + token->start; } \ No newline at end of file