• 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
Issue with buffer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue with buffer


  • Subject: Issue with buffer
  • From: Christiaan Hofman <email@hidden>
  • Date: Mon, 28 Mar 2011 19:09:42 +0200

Xcode 4 reports and issue with the use of a c-array of characters when I use it.

Basically, I create a (fixed length) c-array of characters on the stack in a local variable, then filling it by assigning characters (which I get by parsing some string), keeping track of the length of filled chars, and afterwards I need to access some chars in the buffer. (in particular the last one).

Xcode 4 (analyze) complains that the (indexed) value is garbage.

The code is something like this in pseudo code:

UniChar *buffer;
NSInteger i;
NSInteger bufferCount = 0;
UniChar ch;

for (i = 0; i < length; i++) {
	ch =  (get i-th character from some source);
	if (some condition)
		buffer[bufferCount++] = ch;
}

if (bufferCount > 0) {
	if (buffer[bufferCount - 1] == ' ')  /* <- the left operand of '==' is garbage */
		bufferCount--;
}

(BTW, the code does check the size before it uses a stack buffer.)

Of course this code is perfectly OK, but the compiler doesn't see this.

Is there a way to avoid getting this warning from the compiler?

thanks,
Christiaan

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Xcode4: GCC_AUTO_VECTORIZATION gone?
  • Next by Date: Re: So clicking on entries in the call stack doesn't take you to the source anymore?
  • Previous by thread: Xcode4: GCC_AUTO_VECTORIZATION gone?
  • Next by thread: CoreData Versioning in XCode4
  • Index(es):
    • Date
    • Thread