tags:

views:

82

answers:

2

The following code compiles fine ...

int main (int argc, const char * argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // VARIABLES
    MDD *MDD_structure;
    NSString *mddFile = @"/Users/Gary/Code/Mdd/xTest.mdd";
    NSFileHandle *inFile;
    NSData *inBuffer;
    int MDD_fCount;
    int MDD_vCount;

    // OPEN FILE ON DISK
    inFile = [NSFileHandle fileHandleForReadingAtPath:mddFile];
    if(inFile == nil) NSLog(@"FILE: Open ... ERROR");
    else NSLog(@"FILE: Open ... OK");

    // READ FRAME COUNT
    inBuffer = [inFile readDataOfLength:sizeof(int)];
    [inBuffer getBytes:&MDD_fCount length:sizeof(int)];
    MDD_fCount = CFSwapInt32BigToHost(MDD_fCount);
    NSLog(@"FC: %d", MDD_fCount);

But when I run it through the static analyzer "CLANG LLVM 1.0" I get the following ...

warning: Pass-by-value argument in function call is undefined.
         MDD_fCount = CFSwapInt32BigToHost(MDD_fCount);
                      ^                    ~~~~~~~~~~
1 diagnostic generated.

Can anyone tell me what I am missing?

gary

+4  A: 

You're getting an error because clang isn't convinced that simply passing the address of your variable to a function is the same as giving it a value. You could probably initialize MDD_fCount to 0 to start with to get rid of the error.

John Calsbeek
I have just been looking at this and MDD_fCount does have a value before that call is made, it gets the 32-bytes from the NSData object. Could this just be CLANG missing the fact that I have given MDD_fCount a value directly via its address and not via an assignment?
fuzzygoat
That's what I said—clang has no way to know that "passing the address of your variable to a function" will end up initializing it. It can't statically verify that `-getBytes:length:` will actually entirely populate its parameter.
John Calsbeek
+3  A: 

It means that you haven't initialized MDD_fCount. See this blog post and this other question for additional info.

Martin Gordon
Thank you, should have known, especially as the other question is by me... I will make a note on my monitor for future reference.
fuzzygoat