×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    84

    TPtr8 problem / bug ?

    Hi,

    For the below code the result is:

    Buf1 Length = 12, MaxLength = 88
    Buf2 Length = 17, MaxLength = 88

    The bug appears in 2nd line where max length should be > 119
    since in the code below aPtr8 has been assigned with aBuf2->Des().
    So, after aPtr8 = aBuf2->Des(), it appears I have less space in
    aBuf2 than I allocated in HBufC8::NewLC(119) and aFill copy panics USER 23.

    It appears to be a TPtr8 bug or am I wrong with something ?

    Regards,
    tek

    HBufC8 * aBuf1 = HBufC8::NewLC(85); // aBuf1
    HBufC8 * aBuf2 = HBufC8::NewLC(119); // aBuf2

    TBuf<100> aStr1,aStr2;

    // assign aPtr8 value of buf1
    TPtr8 aPtr8 = aBuf1->Des();
    aPtr8.Copy(_L("Buf1 content"));
    aStr1.Format(_L("Buf1 Length = %d, MaxLength = %d"),aPtr8.Length(),aPtr8.MaxLength());

    // assign aPtr8 value of buf2
    aPtr8 = aBuf2->Des();
    aPtr8.Copy(_L("Buf2 content test"));
    aStr2.Format(_L("Buf2 Length = %d, MaxLength = %d"),aPtr8.Length(),aPtr8.MaxLength());

    RFileWriteStream aFWS;
    TFileName aFN;
    aFN.Copy(_L("c:\\result.txt"));
    aFWS.Replace(CEikonEnv::Static()->FsSession(),aFN,EFileWrite|EFileRead);
    CleanupClosePushL(aFWS); // aFWS

    aFWS.WriteL(aStr1);
    aFWS.WriteL(_L("\r\n"));
    aFWS.WriteL(aStr2);
    aFWS.CommitL();

    // test max len of buf2
    TBuf8<100> aFill; // > 85 and < 119
    aFill.FillZ(aFill.MaxLength()); // length 100

    // aPtr8 is aBuf2 with max len 119
    aPtr8.Copy(aFill); // panics USER 23; no room in aPtr8 == aBuf2 ?

    CleanupStack::PopAndDestroy(3); // aFWS,aBuf2,aBuf1

  2. #2
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    146

    Re: TPtr8 problem / bug ?

    Code:
      HBufC8 * aBuf1 = HBufC8::NewLC(85);	// aBuf1
      HBufC8 * aBuf2 = HBufC8::NewLC(119);		// aBuf2
    
      TBuf<100> aStr1,aStr2;
    
      // assign aPtr8 value of buf1
      TPtr8 aPtr8 = aBuf1->Des();
    Above, the copy constructor of TPtr8 is called, initializing aPtr8 to point to the buffer of aBuf1.

    Code:
    ...
      // assign aPtr8 value of buf2
      aPtr8 = aBuf2->Des();
    Above, aPtr8 points to the buffer in aBuf2 -- Not so... Now the assignment operator is called, copying data from aBuf2 to the buffer pointed to by aPtr8. If you want to change the buffer where the aPtr8 is pointing to, call TPtr8::Set.

    Code:
    ...
      // aPtr8 is aBuf 2 with max len 119
      aPtr8.Copy(a Fill); // panics USER 23; no room in aPtr8 == aBuf2 ?
    So panic happens because aPtr8 is still pointing to the aBuf1 buffer....

  3. #3
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: TPtr8 problem / bug ?

    I would usually use the actual functions provided by the class, since you can not be always sure what "=" does, so Try using Set() fucntion instead.

  4. #4
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    146

    Re: TPtr8 problem / bug ?

    Quote Originally Posted by symbianyucca View Post
    I would usually use the actual functions provided by the class, since you can not be always sure what "=" does, so Try using Set() fucntion instead.
    In this case, TPtr8:perator=() docs say:

    Copies data into this 8 bit modifiable pointer descriptor replacing any existing data. The length of this descriptor is set to reflect the new data.
    So actually you can be sure ;-)

  5. #5
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: TPtr8 problem / bug ?

    Check the contents of aPtr8 before you copy the data in, its probably set to something you do not expect.

    Why? Look at the implementation of operator= in e32cmn.inl - it does not work the way you think it works.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  6. #6
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    84

    Re: TPtr8 problem / bug ?

    Hi,

    Thank you all. As you say, the TPtr8.Set() should be used and more care on the asignment operator = although it is quite confusing in using it; eg if aBuf2->Des() returns a variable and I 'assign' it to aPtr8 that should be 'assignment' and not 'Copy' which overwrite = operator.

    Best to you all. tek

Similar Threads

  1. N70 'contacts' bug problem
    By benbytes in forum General Development Questions
    Replies: 4
    Last Post: 2005-11-09, 20:41
  2. problem in http connection in 3650: is this a bug ?
    By praveenbgupta in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-10-13, 13:25
  3. Weird problem in playing midi with 3300
    By shuto198 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-09-04, 20:01
  4. Replies: 8
    Last Post: 2003-07-11, 12:56
  5. This problem is superseded by a related bug
    By fnagaton in forum Symbian
    Replies: 1
    Last Post: 2003-02-07, 15:14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×