• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: converting C-strings to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: converting C-strings to NSString


  • Subject: Re: converting C-strings to NSString
  • From: Ben Jansen <email@hidden>
  • Date: Mon, 22 Oct 2001 19:40:28 -0700

It looks like you're creating new string objects and losing track of the old secondbuffer. I think all the NSString stringBy*, stringWith*, etc. return new string objects. So secondbuffer after [ secondbuffer stringByAppendingString:scratch ] isn't the same object.

Maybe use this in place of the current secondbuffer assignment:

[ secondbuffer appendString:scratch ];

- Ben

On Monday, October 22, 2001, at 07:26 PM, email@hidden wrote:

Hello.

I have been working on this bug for a while, and I can't seem to figure
out what the problem is. I am first converting a C-string into NSString
using the following syntax:

NSString * scratch;
NSString * secondbuffer;
char buffer[2];

...
[secondbuffer init];

(in a loop)
[scratch initWithCString: buffer];
secondbuffer = [secondbuffer stringByAppendingString: scratch];

This is probably not the best way of doing it, however, it runs fine,
until I do:

NSTextView * results;

...

[results setString:secondbuffer];

Here it screws up, giving me the following error output:

2001-10-22 22:17:19.153 Nmap[2219] *** _NSAutoreleaseNoPool(): Object
0xcfd620 of class NSCFString autoreleased with no pool in place - just
leaking
2001-10-22 22:17:19.154 Nmap[2219] *** _NSAutoreleaseNoPool(): Object
0x14bc190 of class NSCFString autoreleased with no pool in place - just
leaking
2001-10-22 22:17:19.154 Nmap[2219] *** _NSAutoreleaseNoPool(): Object
0x14e0be0 of class NSException autoreleased with no pool in place - just
leaking
2001-10-22 22:17:19.154 Nmap[2219] An uncaught exception was raised
2001-10-22 22:17:19.154 Nmap[2219] *** -[NSTextView
replaceCharactersInRange:withString:]: nil NSString given.
2001-10-22 22:17:19.155 Nmap[2219] *** Uncaught exception:
<NSInvalidArgumentException> *** -[NSTextView
replaceCharactersInRange:withString:]: nil NSString given.

As far as I can figure it, the secondbuffer string gets released? I have
no idea why. It is declared globally, i.e. outside any classes or
functions.

Please help, I am unsure what to do with this. I have been struggling
two whole days with this...

Nick

Nick Hristov
Slayter Box 1194
Denison University
Granville, OH 43023
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >converting C-strings to NSString (From: email@hidden)

  • Prev by Date: converting C-strings to NSString
  • Next by Date: Re: Making an NSString from NSData
  • Previous by thread: converting C-strings to NSString
  • Next by thread: Re: converting C-strings to NSString
  • Index(es):
    • Date
    • Thread