I was trying to add some TStrings together with the + operator and discovered some weird behavior. Unfortunately some of it seems non-deterministic (i.e. I can’t reproduce the results with the same commands in CINT!) This hints at some kind of race/memory issue maybe?
Here is the first example:
[code]* ROOT v5.34/10 *
root [0] TString s1(“foo”)
root [1] TString s2(“bar”)
root [2] s1+s2
(class TString)"“
root [3] s1+s2
(class TString)”“
root [4] s1+s2
(class TString)”“
root [5] s1
(class TString)“foo"
root [6] s2
(class TString)“bar"
root [7] s1+s2
(class TString)”?”???-???”!!!n0.-??“
root [8] s1+s2
(class TString)”"
[/code]
After that s1 and s2 (and their adding) was more consistent. It still gives a blank string for s1+s2 which I think is wrong, but at least it’s consistent! Doing the same order of s1 and s2 operations in a new CINT session does not make the same ???-type TString appear.
Here is another example:
[code]* ROOT v5.34/10 *
root [0] TString s1(“foo”)
root [1] s1 + “bar”
(class TString)"" # Two more times this is consistent, now I try a std::string
root [4] std::string s2(“foo”)
root [5] s2 + “bar”
*** Break *** segmentation violation
Root >
root [6] s2 + “bar”
*** Break *** segmentation violation
Root >
root [7] s2 # I guess std::strings won’t work, but wait. it’s actually a TString?!
(class TString)"foo"
root [8] s1
(class TString)“foo"
root [11] s1 + “bar” # Non-reproducible behavior again, I get ??-type strings!
(class TString)”?:???"
root [12] s2 + “bar”
*** Break *** segmentation violation
Root >
root [13]
[/code]
Every time I try to reproduce this behavior it returns to the useless-but-consistent behavior that adding TStrings together with “+” results in an empty TString, as does adding a TString with a char * literal, and adding an std::string with a char * literal gives a seg fault. The last one is apparently actually incorrect as adding std::strings with char * literals should give a new std::string, but CINT claims that the std::string is actually a TString, but this TString behaves differently than “actual” TStrings (which don’t seg fault when you try to add char *s).
Can someone help me figure out what’s going on? I’m using ROOT 5.34/10 from MacPorts compiled with Clang 3.2 (also from MacPorts), on Mac OSX 10.7.5.
Jean-François