Faulty [] operator on TBuf in 3rd Edition
| Tue, 2007-01-02 23:50 | |
|
Here's a fun little undocumented (maybe bug, maybe not) "feature" of Symbian OS 9 (3rd Edition) which used to work in the second edition.
Works on 2nd, not on 3rd edition: Code: TBuf<32> buf; RDebug::Print(_L("len: %d buflen: %d %d"), strlen(aFileName), buf.Length(), buf.MaxLength() ); // outputs 0, 32 for (size_t i = 0; i <= strlen(aFileName); i++) { buf[i] = aFileName[i]; } Now it works on the 3rd edition: Code: TBuf<32> buf; buf = _L("12345678901234567890123456789012"); RDebug::Print(_L("len: %d buflen: %d %d"), strlen(aFileName), buf.Length(), buf.MaxLength() ); // outputs 32, 32 for (size_t i = 0; i <= strlen(aFileName); i++) { buf[i] = aFileName[i]; } The deal was that the operator[] call on buf was causing a USER 9 panic. This never happened in the 2nd Edition. I think the problem would be solved if you added buf.SetMax(); after the declaration, although I hadn't tested that out. Since I spent way too long tracking down this problem, I just thought you guys might want to know. -euroq |
|






Forum posts: 732
Now check your for loop: it's i = 0; i <= strlen(aFileName) so that means in this case 0 - 32, right.
Now see this SDK Help:
So I think anIndex is becoming greater than the current length of this descriptor.
try changing the for loop to: i = 0; i < strlen(aFileName); may work.
Forum posts: 149
buf[0] = 'A'; // will cause USER 9 because buf's length is 0
buf = _L("ABC");
TChar c = buf[0]; // length of buf is 3, so buf[0] works
buf[0] = 'A'; // now this works because length is 3
Forum posts: 110
buf[0] = 'A'; // will cause USER 9 because buf's length is 0
I'd be very surprised if this code behaves differently on S60 second edition. The behaviour here was determined a very long time ago (EPOC ER5 and earlier I'm sure)
A newly created TBuf is empty, so it doesn't have any elements to access. It has always been this way. Are you absolutely sure that you are not getting a panic on S60 V2?
Forum posts: 149
I stand corrected. It never worked on 2nd edition. This whole time I thought that a TBuf was an array. My bad.
It turns out that while stress testing the application something happened which never happened in the 2nd edition.
-euroq