From 76d7acfbb77ec16a3ea203ab625fc7c37bcf3691 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 1 May 2012 15:10:59 +0200 Subject: [PATCH] Fixed JSON lib automatic conversion from string to long long int. --- util/json.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/util/json.cpp b/util/json.cpp index 2799c9f1..8d4b319f 100644 --- a/util/json.cpp +++ b/util/json.cpp @@ -3,6 +3,7 @@ #include "json.h" #include #include +#include int JSON::Value::c2hex(int c){ if (c >= '0' && c <= '9') return c - '0'; @@ -252,9 +253,15 @@ JSON::Value & JSON::Value::operator=(const unsigned int &rhs){ return ((*this) = (long long int)rhs); } -/// Automatic conversion to long long int - returns 0 if not an integer type. +/// Automatic conversion to long long int - returns 0 if not convertable. JSON::Value::operator long long int(){ - return intVal; + if (myType == INTEGER){ + return intVal; + } + if (myType == STRING){ + return atoll(strVal.c_str()); + } + return 0; }