Question

Clang's static analyzer is giving me a warning where I am setting mti.bounds below. It says

Logic Error - Passed-by-value struct argument contains uninitialized data

-(void)setLabelWithIndex:(int)idx signlop:(int)silop {
   int domsi= 0;
   msi= [sls objectAtIndex:idx];
   float fs= (fontFactor*mapyd)/mapH;
   if (fs< 10){  //minfont
      fs= 10;
   }else if(fs> 36){
      fs= 36;
   }
   if (signs[silop].turn){
      domsi= 1;
      [msi setFont:[UIFont fontWithName:@"Arial-BoldMT" size:1.25*fs]];
      msi.text= @"T";
      msi.backgroundColor= [UIColor clearColor];
      if (silop== editLastLop){
         msi.textColor= [UIColor yellowColor];
      }else{
         msi.textColor= turnMinderColor;
      }
      msi.layer.borderWidth= 0;
   }else if(signs[silop].trap){
      if (numTrapsShowing< numTrapImages){
         domsi= 0;
         numTrapsShowing++;
         lopOfTrap[numTrapsShowing-1]= silop;
         mti= [sts objectAtIndex:numTrapsShowing-1];
         CGRect butbounds;
         butbounds.size = CGSizeMake(1.25*fs, 3.5*fs);
         mti.bounds = butbounds;    // Analyzer warns here
      }else{
         domsi= -1;
      }
   }else{

Here's a screenshot of the analyzer output:

enter image description here

What am I doing wrong?

Was it helpful?

Solution

You need to take the existing bounds, modify it and set it back again:

CGRect bitbounds = mti.bounds;
bitbounds.size = CGSizeMake(1.25*fs, 3.5*fs);
mti.bounds = bitbounds;

This is because the bounds property uses a CGRect copy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top