Odd behavior with strings in structs

thothrisingthothrising Member Posts: 9
When I include strings in structs it seems to impact/change other values if there is more than one other variable before the string. Take the contract:
contract buggystruct {
  Buggy public bug;

  struct Buggy {
    uint first;
    uint second;
    uint third;
    string last;
  }

  function buggystruct(){
    bug = Buggy(10, 20, 30, "a");
  }
}
Checking the saved values in the struct with:

> buggystruct.bug()

gives:

['10', '1', '43874346312576839672212443538448152585028080127215369968075725190498334277632', 'a' ]

The first uint and string are correct, but obviously the second and third uints are not. If we only have one uint and then a string in the struct, all is well:
contract buggystruct {
  Buggy public bug;

  struct Buggy {
    uint first;
    string last;
  }

  function buggystruct(){
    bug = Buggy(10, "a");
  }
}
then:

>buggystruct.bug()

['10', 'a']

As we would expect.

Two uints and then a string also cause the second uint to be wrong, and if you change the value of the string, the change that occurs in the second (and third) uints also change.

I'm using the online solidity compiler. Am I doing something stupid? Or is there an issue with strings in structs? Or is this a compiler/language/geth client issue?

I can't find any mention of a string in structs issue in the solidity wiki, and as it is worded it seems this should work. Is this a bug? Has anyone else run into this or can see what I'm doing wrong?

Thanks.

Comments

Sign In or Register to comment.