0

以下来自CocoaLumberjackDDAbstractDatabaseLogger的方法:

- (void)createAndStartDeleteTimer
{
    if ((deleteTimer == NULL) && (deleteInterval > 0.0) && (maxAge > 0.0))
    {
        deleteTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, loggerQueue);

        if (deleteTimer != NULL) {
            dispatch_source_set_event_handler(deleteTimer, ^{ @autoreleasepool {

                [self performDelete];

            }});

            [self updateDeleteTimer];

            dispatch_resume(deleteTimer);
        }
    }
}

- (void)updateDeleteTimer
{
    if ((deleteTimer != NULL) && (deleteInterval > 0.0) && (maxAge > 0.0))
    {
        uint64_t interval = (uint64_t)(deleteInterval * NSEC_PER_SEC);
        dispatch_time_t startTime;

        if (lastDeleteTime > 0)
            startTime = dispatch_time(lastDeleteTime, interval);
        else
            startTime = dispatch_time(DISPATCH_TIME_NOW, interval);

        dispatch_source_set_timer(deleteTimer, startTime, interval, 1.0);
    }
}

触发 clang 静态分析器警告:

CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m:207:13: Null pointer passed as an argument to a 'nonnull' parameter

步骤截图: 在此处输入图像描述

我查看了我的构建输出,发现了以下 plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>clang_version</key>
<string>Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)</string>
 <key>files</key>
 <array>
  <string>CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m</string>
 </array>
 <key>diagnostics</key>
 <array>
  <dict>
   <key>path</key>
   <array>
    <dict>
     <key>kind</key><string>control</string>
     <key>edges</key>
      <array>
       <dict>
        <key>start</key>
         <array>
          <dict>
           <key>line</key><integer>194</integer>
           <key>col</key><integer>2</integer>
           <key>file</key><integer>0</integer>
          </dict>
          <dict>
           <key>line</key><integer>194</integer>
           <key>col</key><integer>3</integer>
           <key>file</key><integer>0</integer>
          </dict>
         </array>
        <key>end</key>
         <array>
          <dict>
           <key>line</key><integer>194</integer>
           <key>col</key><integer>7</integer>
           <key>file</key><integer>0</integer>
          </dict>
          <dict>
           <key>line</key><integer>194</integer>
           <key>col</key><integer>17</integer>
           <key>file</key><integer>0</integer>
          </dict>
         </array>
       </dict>
      </array>
    </dict>

<!-- Lots of the same style of line, col, file key-values in dicts and arrays -->

   </array>
   <key>description</key><string>Null pointer passed as an argument to a &apos;nonnull&apos; parameter</string>
   <key>category</key><string>API</string>
   <key>type</key><string>Argument with &apos;nonnull&apos; attribute passed null</string>
  <key>issue_context_kind</key><string>Objective-C method</string>
  <key>issue_context</key><string>createAndStartDeleteTimer</string>
  <key>issue_hash</key><integer>14</integer>
  <key>location</key>
  <dict>
   <key>line</key><integer>207</integer>
   <key>col</key><integer>13</integer>
   <key>file</key><integer>0</integer>
  </dict>
  </dict>
 </array>
</dict>
</plist>

有什么方法可以获取静态分析器认为会导致传入空指针的抽象值?我想不通。

4

1 回答 1

0

也许晚了,但是对于看到的步骤,您可以运行独立的命令行scan-build实用程序,它使用相同的 clang 静态分析器,但会向您显示触发警告的步骤

于 2013-09-03T07:32:12.627 回答