When i build and anylayse my app , i get the below memeory warning
"The left operand of '>' is a garbage value" at this line isTrue = (newLength > 20) ? NO : YES;
What is the problem over here.Thanks for any help
(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength;
BOOL isTrue;
if(textField == txtFirstName){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 20) ? NO : YES;
}
if(textField == txtLastName){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 20) ? NO : YES;
}
if(textField == txtEmail){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 100) ? NO : YES;
}
if(textField == txtCompanyName){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
if(textField == txtPassword){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
if(textField == txtRe_EnterPassword){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
if(textField == txtZipCode){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 20) ? NO : YES;
}
if(textField == txtCountry){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
isTrue = (newLength > 20) ? NO : YES;
return isTrue;
}
The problem occurs when all of the if conditions fail, ie. if textField
is not one of the set you are expecting it to be.
In this case, newLength
is never assigned to, and will be a random garbage value.
Whilst this is probably "never going to happen", the static analyzer is not aware of that.
You should initialize newLength
to have a default value, perhaps zero.
the analyzer cannot confirm that your 'switch-like construct' does not 'fall through'. newLength
's value may never be set if all those if cases fail. then in that event, it would qualify as a garbage value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With