Commits

sn...@snej.local  committed 5ade3e0

Fixed some problems reported by the CLANG static analyzer.

  • Participants
  • Parent commits d6ab9f5

Comments (0)

Files changed (5)

 
 NSTimeInterval TimeIntervalSinceBoot(void)
 {
-    // From http://developer.apple.com/qa/qa2004/qa1398.html
-    uint64_t abstime = mach_absolute_time();
-    // Have to do some pointer fun because AbsoluteToNanoseconds
+    // Adapted from http://developer.apple.com/qa/qa2004/qa1398.html
+    // Have to do some union tricks because AbsoluteToNanoseconds
     // works in terms of UnsignedWide, which is a structure rather
     // than a proper 64-bit integer.
-    Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &abstime );
-    return *(uint64_t*)&elapsedNano / 1.0e9;
+    union {
+        uint64_t asUInt64;
+        UnsignedWide asUWide;
+    } t;
+    t.asUInt64 = mach_absolute_time();
+    t.asUWide = AbsoluteToNanoseconds(t.asUWide);
+    return t.asUInt64 / 1.0e9;
 }
 
 
         }
         
         if( ! CheckOSErr(err,error) ) {
-            Warn(@"FileAlias init failed with OSStatus %i",err);
+            Warn(@"FileAlias init failed with OSStatus %i for %@",err,targetPath);
             [self release];
             return nil;
         }
 
     self = [super init];
     if( self ) {
-        Handle handle;
+        Handle handle = NULL;
         unsigned length;
         const void *bytes = [arch decodeBytesForKey:@"aliasHandle" returnedLength: &length];
         if( bytes )
 #define Warn Warn
 
 void AlwaysLog( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
-BOOL _WillLogTo( NSString *domain );
 BOOL EnableLog( BOOL enable );
 #define EnableLogTo( DOMAIN, VALUE )  _EnableLogTo(@""#DOMAIN, VALUE)
+#define WillLog()  _WillLogTo(nil)
 #define WillLogTo( DOMAIN )  _WillLogTo(@""#DOMAIN)
 
 
 {
     if( _gShouldLog == -1 )
         InitLogging();
-    return _gShouldLog && [sEnabledDomains containsObject: domain];
+    return _gShouldLog && (domain==nil || [sEnabledDomains containsObject: domain]);
 }
 
 BOOL _EnableLogTo( NSString *domain, BOOL enable )
     // HTTP status >= 300 is considered an error:
     int status = self.statusCode;
     if( status >= 300 ) {
-        NSString *reason = NSLocalizedStringFromTable( @"HTTP_ERROR_MESSAGE",@"UKCrashReporter",@"");
-        reason = [NSHTTPURLResponse localizedStringForStatusCode: status];
+        NSString *reason = [NSHTTPURLResponse localizedStringForStatusCode: status];
         NSDictionary *info = $dict({NSLocalizedFailureReasonErrorKey,reason});
         return [NSError errorWithDomain: MyHTTPErrorDomain code: status userInfo: info];
     } else