-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parser cannot handle numbers #48
Comments
That's strange. Can you provide more details? QJson has an extensive test suite which would have spotted this issue. |
My function is:
#############################################
JSON from serializing I am using is: Number is out of range: 4 It works if I use request.insert(""parameters, QString::number(channelNumber)); |
I'm a bit confused, can you just write down the json data you are trying to convert to a |
BTW, I tried to do something like that: void TestSerializer::testFoo()
{
Serializer serializer;
Parser parser;
QVariantMap request;
bool ok;
quint64 num = 4;
request.insert(QLatin1String("parameters"), num);
request.insert(QLatin1String("command"), QLatin1String("foo"));
const QByteArray json = serializer.serialize( request, &ok);
QVERIFY( ok );
qDebug() << json;
QByteArray expected = "null";
QVariant writtenThenRead = parser.parse( json, &ok );
QVERIFY(ok);
qDebug() << writtenThenRead;
} But everything works fine when using latest version of QJson from git:
|
It seems to me that this issue might be due to usage of global variable errno in multithreaded environment. Yet this problem has occurred systematically and reliably with me. I'm not sure. But anyway, in json_scanner.yy/cc there is usage of method strtoull() and afterwards there is test about global error variable errno. This is prone to break if any method anywhere sets errno, including everything in stdio.h etc. Fortunately there is also easy fix as according to documentation strtoull will return ULLONG_MAX if number is too large and this return value naturally is not affected by MT environment. So I fixed the problem this way:
Here 2 additional things might be considered if anyone is willing to commit this into version control too: 1: removal of the printf() as it was for me only and 2: removal of the conditioning with errno as it really is not thread safe. I have been using qjson in a program that happily parses in multiple threads and also does IO so .. errno just might come up for whatever reason. Also it might be worth mentioning that the problem occurred only in MinGW build. In linux I have never seen this. |
Hello flavio, I am reproducing this issue with on the dev/master with your code example.
Do you have any clue ? |
Reseting |
yeh,i have the same problem. |
strtoll and strtoull may not reset errno for valid input. Need to check actual returned value as sayed in strtoll documentation. Fix flavio#48
strtoll and strtoull may not reset errno for valid input. Need to check actual returned value as sayed in strtoll documentation. Fix flavio#48
strtoll and strtoull may not reset errno for valid input. Need to check actual returned value as sayed in strtoll documentation. Fix flavio#48
strtoll and strtoull may not reset errno for valid input. Need to check actual returned value as sayed in strtoll documentation. Fix flavio#48
Parser cannot handle numbers. Pass in a number as value and get
Number is out of range: 0
The text was updated successfully, but these errors were encountered: