Warning: comparing constant 8 with an expression of type XXXX is always incorrect

I used ASIHTTPRequest in my project, but in the file ASIDataCompressor.m line 190 :

 if ([inputStream streamStatus] == NSStreamEventErrorOccurred) { if (err) { *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were unable to write to the destination data file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,[outputStream streamError],NSUnderlyingErrorKey,nil]]; } [compressor closeStream]; return NO; } 

this warns me about this:

Warning

Does anyone know how to fix this? THX

+8
comparison objective-c warnings nsstream
source share
2 answers

(NSStreamStatus)NSStreamEventErrorOccurred

change

Perhaps the right way to handle this is to replace NSStreamEventErrorOccurred with NSStreamStatusError . This is probably what ASIHTTP wanted.

+17
source share

NSStreamEventErrorOccurred is of type NSStreamEvent with a constant value of 8 . The streamStatus method returns NSStreamStatus not NSStreamEvent and NSStreamStatus does not exceed 7 , so you got an error. You are fortunate that 8 exceeded the bounds and you received an error message because this is not always the case, so you should always be careful with the return type.

+6
source share

All Articles