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
textFieldis not one of the set you are expecting it to be.In this case,
newLengthis 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
newLengthto have a default value, perhaps zero.