{"id":14494,"date":"2016-05-10T11:48:44","date_gmt":"2016-05-10T15:48:44","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14494"},"modified":"2016-05-11T09:21:54","modified_gmt":"2016-05-11T13:21:54","slug":"some-static-analyzer-warnings-off-by-default","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/05\/10\/some-static-analyzer-warnings-off-by-default\/","title":{"rendered":"Some Static Analyzer Warnings Off by Default"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/steipete\/status\/727762354079944704\">Peter Steinberger<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/steipete\/status\/727762354079944704\">\n<p>The Static Analyzer in Xcode 7.3 learned a few new tricks that are off by default.<\/p>\n<\/blockquote>\n<p>I added the following to my <tt>xcconfig<\/tt> file:<\/p>\n<pre>CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES\nCLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES\nCLANG_ANALYZER_NONNULL = YES\nCLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES\nCLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES\nCLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES<\/pre>\n<p><a href=\"https:\/\/twitter.com\/_nb\/status\/727785237833498626\">Nicolas<\/a> <a href=\"https:\/\/twitter.com\/_nb\/status\/727785331303567360\">Bouilleaud<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/_nb\/status\/727785237833498626\"><p>I thought &ldquo;Missing localizability&rdquo; was about missing translations, which would be super useful.<\/p><\/blockquote>\n<blockquote cite=\"https:\/\/twitter.com\/_nb\/status\/727785331303567360\"><p>Instead, it warns when using raw, unlocalized NSStrings into UI methods. Which is cool, but less useful.<\/p><\/blockquote>\n<blockquote cite=\"https:\/\/twitter.com\/_nb\/status\/727785415042842625\"><p>Now how does clang know which API is &ldquo;UI&rdquo;? <a href=\"http:\/\/clang.llvm.org\/doxygen\/LocalizationChecker_8cpp_source.html#l00154\">Behold<\/a><\/p><\/blockquote>\n<p>It&rsquo;s pretty impressive in that it can even find an <code>NSString<\/code> that&rsquo;s used to create an <code>NSAttributedString<\/code> that&rsquo;s used for a menu title. However, it also finds some false positives because it assumes that every string needs to be localized. For some that doesn&rsquo;t make sense. And others, such as my alert help anchors, may not need to be based on your specific situation.<\/p>\n<p><a href=\"http:\/\/clang-analyzer.llvm.org\/faq.html#exclude_code\">Clang<\/a>:<\/p>\n<blockquote cite=\"http:\/\/clang-analyzer.llvm.org\/faq.html#exclude_code\"><p>If your project deliberately uses unlocalized user-facing strings (for example, in a debugging UI that is never shown to users), you can suppress the analyzer warnings (and document your intent) with a function that just returns its input but is annotated to return a localized string.<\/p>\n<p>[&#8230;]<\/p>\n<p>There is currently no solid mechanism for suppressing an analyzer warning, although this is currently being investigated.<\/p><\/blockquote>\n<p>However:<\/p>\n<blockquote cite=\"http:\/\/clang-analyzer.llvm.org\/faq.html#exclude_code\"><p>When the static analyzer is using clang to parse source files, it implicitly defines the preprocessor macro <code>__clang_analyzer__<\/code>. One can use this macro to selectively exclude code the analyzer examines.<\/p><\/blockquote>\n<p>I&rsquo;m using that because the analyzer complains about an <code>AuthorizationItem.value<\/code> being <code>NULL<\/code> even though the documentation says it can be.<\/p>\n\n<p>Update (2016-05-11): Note that the analyzer warnings don&rsquo;t work for Swift code.<\/p>","protected":false},"excerpt":{"rendered":"<p>Peter Steinberger: The Static Analyzer in Xcode 7.3 learned a few new tricks that are off by default. I added the following to my xcconfig file: CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES CLANG_ANALYZER_NONNULL = YES CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES Nicolas Bouilleaud: I thought &ldquo;Missing localizability&rdquo; was about missing translations, which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[230,31,309,30,54,71,226],"class_list":["post-14494","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-clang","tag-ios","tag-localization","tag-mac","tag-objective-c","tag-programming","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=14494"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14494\/revisions"}],"predecessor-version":[{"id":14500,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14494\/revisions\/14500"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}