cxflag203 / superobject

Automatically exported from code.google.com/p/superobject
0 stars 0 forks source link

Clone for stNull gives AV #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

var
  j1, j2, j3: ISuperObject;
begin
  j1 := SO('{a:null}');
  j2 := j1.Clone;
  j3 := j2.Clone;
end;

What is the expected output? What do you see instead?
No AV.

What version of the product are you using? On what operating system?
Latest from svn (r54)

Please provide any additional information below.
Function TSuperObject.Clone for stNull returns nil. However parsing JSON object 
creates stNull object (not nil).

It should create be:
function TSuperObject.Clone: ISuperObject;
var
  ite: TSuperObjectIter;
  arr: TSuperArray;
  j: integer;
begin
  case FDataType of
    stNull: Result := TSuperObject.Create(stNull); <- add this
    stBoolean: ...

You could also add a check in Clone function, however I think that it should be 
consistent with Load/Parse. But I see that similar check was added in Merge 
function (r37). So I'm not sure which one is more correct. Maybe both, so add 
check in Clone for nil and clone stNull as TSuperObject.Create(stNull)?

Original issue reported on code.google.com by krystian...@gmail.com on 22 Mar 2013 at 1:32

GoogleCodeExporter commented 9 years ago
in the interator, could check for a nil val too: 
function TSuperObject.Clone: ISuperObject;
var
  ite: TSuperObjectIter;
  arr: TSuperArray;
  j: integer;
begin
...
    stObject:
      begin
        Result := TSuperObject.Create(stObject);
        if ObjectFindFirst(self, ite) then
        with Result.AsObject do
        repeat
          if ite.val<>Nil then
            PutO(ite.key, ite.val.Clone)
          else
            PutO(ite.key, Nil);
        until not ObjectFindNext(ite);
        ObjectFindClose(ite);
      end;

Original comment by hubert.t...@gmail.com on 12 Dec 2013 at 5:40