Issue with buffer
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