#1 2021-01-24 07:11:06

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

mORMot2: seems JsonArrayCount(P, PMax) always returns 0 for huge input

I'm not sure that the problem is there, but I got stuck (or tired) in debugging.

It seems that the problem appears only for big JSON arrays. Procedure _JL_DynArray exits with an invalid context result after guessing the array count(=0).
Considering the logic of the code (like result := -result and so on) I tried to change

function JsonArrayCount(P, PMax: PUtf8Char): integer;
begin
  result := -1;
  ...

It helps for the huge input but breaks the parsing of smaller arrays...

Offline

#2 2021-01-24 13:55:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: mORMot2: seems JsonArrayCount(P, PMax) always returns 0 for huge input

For a huge array, JsonArrayCount() should return a negative number, not 0.
Then _JL_DynArray() should use the abs() value as initial guess for its array size, then grow up on need.

The problem was not if the JSON array was big (I did test that), but if the first item of the JSON array was big (I didn't test it).
Then PMax was reached before the count was 1, and it falsely returned 0.

Should be fixed now.
Thanks for the input!

Offline

#3 2021-01-24 15:21:02

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: mORMot2: seems JsonArrayCount(P, PMax) always returns 0 for huge input

Ah, I see. Tested the new version, all works, nice! Thanks for the fix and the explanation!

Offline

Board footer

Powered by FluxBB