• 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
Strange Warning Message from the Analyzer?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange Warning Message from the Analyzer?


  • Subject: Strange Warning Message from the Analyzer?
  • From: Dave <email@hidden>
  • Date: Tue, 09 Jun 2015 13:35:11 +0100

Hi All,

Mac project, XCode 6.3.1, non ARC.

I’m getting the following Analyzer (Blue) Warnings in the method below (see comments):

-(void) insertIndexes:(NSUInteger*) theIndexBufferPtr length:(NSInteger) theInsertLength atPosition:(NSUInteger) thePosition
{
void*					myOriginalBaseBufferPtr;
NSUInteger*				myInsertIndexBufferPtr;
NSUInteger*				mySourceIndexBufferPtr;
NSUInteger*				myDestIndexBufferPtr;
NSUInteger				myNewLength;
NSUInteger				myCopyLength;
NSUInteger				myIndex;
NSInteger				myInsertPosition;

if (theInsertLength <= 0)
	return;

myOriginalBaseBufferPtr = NULL;

if (thePosition >= self.pIndexLength)
	myInsertPosition = self.pIndexLength;
else
	myInsertPosition = thePosition;

myOriginalBaseBufferPtr = NULL;
myNewLength = self.pIndexLength + theInsertLength;
if (myNewLength == self.pIndexLength)
	return;

myInsertIndexBufferPtr = theIndexBufferPtr;
myOriginalBaseBufferPtr = [self claimIndexBuffer];
mySourceIndexBufferPtr = myOriginalBaseBufferPtr;

if (myNewLength > self.pIndexMaximumLength)
	self.pIndexMaximumLength = myNewLength;

[self setupIndexBuffer];								//This sets self.pIndexBaseBufferPtr to a buffer created with malloc()
myDestIndexBufferPtr = self.pIndexBaseBufferPtr;

//**
//**	Copy the Buffer Up to the Insert Position
//**
myCopyLength = myInsertPosition - 1;
while(myCopyLength > 0)
	{
	myIndex = *mySourceIndexBufferPtr;
	*myDestIndexBufferPtr = myIndex;						//********** Warning Dereference of null pointer (loaded from variable myDestIndexBufferPtr)

	mySourceIndexBufferPtr++;
	myDestIndexBufferPtr++;
	myCopyLength--;
	}

//**
//**	Copy the Indexes to Insert to the Destination Buffer
//**
myCopyLength = theInsertLength;
while(myCopyLength > 0)
	{
	myIndex = *myInsertIndexBufferPtr;
	*myDestIndexBufferPtr = myIndex;					//********** Warning Dereference of null pointer (loaded from variable myDestIndexBufferPtr)

	myInsertIndexBufferPtr++;
	myDestIndexBufferPtr++;
	myCopyLength--;
	}

//**
//**	Copy the Remaining Part of the Original Buffer
//**
myCopyLength = self.pIndexLength - thePosition;
while(myCopyLength > 0)
	{
	myIndex = *mySourceIndexBufferPtr;
	*myDestIndexBufferPtr = myIndex;

	mySourceIndexBufferPtr++;
	myDestIndexBufferPtr++;
	myCopyLength--;
	}

self.pIndexLength = myNewLength;

if (myOriginalBaseBufferPtr != NULL)
	free(myOriginalBaseBufferPtr);
}


The properties are defined as so:

@property (nonatomic,assign)			void*						pIndexBaseBufferPtr;
@property (nonatomic,assign)			NSUInteger					pIndexBaseBufferSize;
@property (nonatomic,assign)			NSUInteger					pIndexLength;
@property (nonatomic,assign)			NSUInteger					pIndexMaximumLength;


Any ideas why its giving a warning? It all looks fine to me or am I missing something? From clicking on the warning in XCode, I it thinks “setupIndexBuffer” is setting self. pIndexBaseBufferPtr to NULL. But here is that method and it doesn’t!

-(void) setupIndexBuffer
{
void*				myBaseBufferPtr;

if (self.pIndexBaseBufferPtr != NULL)
	free(self.pIndexBaseBufferPtr);

self.pIndexBaseBufferSize = (self.pIndexMaximumLength * sizeof(NSUInteger));
myBaseBufferPtr = malloc(self.pIndexBaseBufferSize);
self.pIndexBaseBufferPtr = myBaseBufferPtr;

[self clearIndexBuffer];
}

I suppose I could change this code to read:

self.pIndexBaseBufferPtr = [self setupIndexBuffer];
myDestIndexBufferPtr = self.pIndexBaseBuffer;

And change it wherever it’s referenced (this in an internal private method), but I shouldn’t need to?

All the Best
Dave



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Strange Warning Message from the Analyzer?
      • From: Steve Mills <email@hidden>
  • Prev by Date: Re: Wanted: Elegant way to manage this task
  • Next by Date: Re: Strange Warning Message from the Analyzer?
  • Previous by thread: Re: Wanted: Elegant way to manage this task
  • Next by thread: Re: Strange Warning Message from the Analyzer?
  • Index(es):
    • Date
    • Thread