Title: [284977] trunk/Tools
Revision
284977
Author
ddkil...@apple.com
Date
2021-10-28 08:12:06 -0700 (Thu, 28 Oct 2021)

Log Message

[Tools] Enable -Wformat=2 warnings
<https://webkit.org/b/232404>
<rdar://problem/84728058>

Reviewed by Darin Adler.

* DumpRenderTree/mac/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
* ImageDiff/cg/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
* MiniBrowser/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
* MobileMiniBrowser/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
* TestWebKitAPI/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
- Add -Wformat=2 switch, which includes -Wformat-nonliteral.

* TestWebKitAPI/PlatformUtilities.h:
(TestWebKitAPI::Util::waitForConditionWithLogging):
- Add NS_FORMAT_FUNCTION() attribute.
* TestWebKitAPI/Tests/WebKitCocoa/LoadAlternateHTMLString.mm:
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
(TEST):
- Change type of format string to `NSString *const`.
* TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerTCPServer.h:
(ServiceWorkerTCPServer::request):
(ServiceWorkerTCPServer::requestWithLocalhost):
(ServiceWorkerTCPServer::requestWithFragment):
- Call -[NSString initWithFormat:] in each method so the format
  string is used directly in the method call.
(ServiceWorkerTCPServer::respondToRequests):
- Change type of format string to `NSString *const`, and fix
  placeholder for strlen() return value.
(ServiceWorkerTCPServer::requestWithFormat): Delete.
(ServiceWorkerTCPServer::requestWithURLString):
- Rename from requestWithFormat() and take a `url` parameter
  instead of a `format` parameter.
* TestWebKitAPI/cocoa/HTTPServer.mm:
(TestWebKitAPI::HTTPServer::request const):
- Change switch statement to set the scheme for the URL, and
  move the format string into +[NSString stringWithFormat:].

* WebEditingTester/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
* WebKitTestRunner/Configurations/Base.xcconfig:
(WARNINGS_CFLAGS):
- Add -Wformat=2 switch, which includes -Wformat-nonliteral.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (284976 => 284977)


--- trunk/Tools/ChangeLog	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/ChangeLog	2021-10-28 15:12:06 UTC (rev 284977)
@@ -1,3 +1,55 @@
+2021-10-28  David Kilzer  <ddkil...@apple.com>
+
+        [Tools] Enable -Wformat=2 warnings
+        <https://webkit.org/b/232404>
+        <rdar://problem/84728058>
+
+        Reviewed by Darin Adler.
+
+        * DumpRenderTree/mac/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        * ImageDiff/cg/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        * MiniBrowser/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        * MobileMiniBrowser/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        * TestWebKitAPI/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        - Add -Wformat=2 switch, which includes -Wformat-nonliteral.
+
+        * TestWebKitAPI/PlatformUtilities.h:
+        (TestWebKitAPI::Util::waitForConditionWithLogging):
+        - Add NS_FORMAT_FUNCTION() attribute.
+        * TestWebKitAPI/Tests/WebKitCocoa/LoadAlternateHTMLString.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
+        (TEST):
+        - Change type of format string to `NSString *const`.
+        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerTCPServer.h:
+        (ServiceWorkerTCPServer::request):
+        (ServiceWorkerTCPServer::requestWithLocalhost):
+        (ServiceWorkerTCPServer::requestWithFragment):
+        - Call -[NSString initWithFormat:] in each method so the format
+          string is used directly in the method call.
+        (ServiceWorkerTCPServer::respondToRequests):
+        - Change type of format string to `NSString *const`, and fix
+          placeholder for strlen() return value.
+        (ServiceWorkerTCPServer::requestWithFormat): Delete.
+        (ServiceWorkerTCPServer::requestWithURLString):
+        - Rename from requestWithFormat() and take a `url` parameter
+          instead of a `format` parameter.
+        * TestWebKitAPI/cocoa/HTTPServer.mm:
+        (TestWebKitAPI::HTTPServer::request const):
+        - Change switch statement to set the scheme for the URL, and
+          move the format string into +[NSString stringWithFormat:].
+
+        * WebEditingTester/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        * WebKitTestRunner/Configurations/Base.xcconfig:
+        (WARNINGS_CFLAGS):
+        - Add -Wformat=2 switch, which includes -Wformat-nonliteral.
+
 2021-10-27  Jonathan Bedard  <jbed...@apple.com>
 
         [webkitscmpy] Generate commit message template

Modified: trunk/Tools/DumpRenderTree/mac/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/DumpRenderTree/mac/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/DumpRenderTree/mac/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -83,7 +83,7 @@
 // FIXME: <http://webkit.org/b/118590> DumpRenderTree should build with -Wshorten-64-to-32
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=arm64*] = NO;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=x86_64] = NO;
-WARNING_CFLAGS = -Wall -W -Wconditional-uninitialized -Wno-unused-parameter -Wundef;
+WARNING_CFLAGS = -Wall -W -Wconditional-uninitialized -Wformat=2 -Wno-unused-parameter -Wundef;
 
 DEBUG_DEFINES = NDEBUG;
 DEBUG_DEFINES[config=Debug] = ;

Modified: trunk/Tools/ImageDiff/cg/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/ImageDiff/cg/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/ImageDiff/cg/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -63,7 +63,7 @@
 GCC_WARN_UNDECLARED_SELECTOR = YES;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=arm64*] = NO;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=x86_64] = NO;
-WARNING_CFLAGS = -Wall -W -Wno-unused-parameter -Wundef
+WARNING_CFLAGS = -Wall -W -Wformat=2 -Wno-unused-parameter -Wundef;
 
 DEBUG_DEFINES = NDEBUG;
 DEBUG_DEFINES[config=Debug] = ;

Modified: trunk/Tools/MiniBrowser/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/MiniBrowser/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/MiniBrowser/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -67,7 +67,7 @@
 CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
 CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
-WARNING_CFLAGS = -Wall -W -Wno-unused-parameter
+WARNING_CFLAGS = -Wall -W -Wformat=2 -Wno-unused-parameter;
 GCC_NO_COMMON_BLOCKS = YES;
 
 SUPPORTED_PLATFORMS = iphoneos iphonesimulator macosx appletvos appletvsimulator watchos watchsimulator;

Modified: trunk/Tools/MobileMiniBrowser/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/MobileMiniBrowser/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/MobileMiniBrowser/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -79,7 +79,7 @@
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=x86_64] = NO;
 MTL_ENABLE_DEBUG_INFO = NO;
 VALIDATE_PRODUCT = YES;
-WARNING_CFLAGS = -Wall -W -Wno-unused-parameter -Wundef
+WARNING_CFLAGS = -Wall -W -Wformat=2 -Wno-unused-parameter -Wundef;
 
 SUPPORTED_PLATFORMS = iphoneos iphonesimulator;
 SDKROOT = $(SDKROOT_$(USE_INTERNAL_SDK));

Modified: trunk/Tools/TestWebKitAPI/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/TestWebKitAPI/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/TestWebKitAPI/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -72,7 +72,7 @@
 CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=arm64*] = NO;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=x86_64] = NO;
-WARNING_CFLAGS = -Wall -W -Wno-unused-parameter -Wthread-safety
+WARNING_CFLAGS = -Wall -W -Wformat=2 -Wno-unused-parameter -Wthread-safety;
 
 DEBUG_DEFINES = NDEBUG;
 DEBUG_DEFINES[config=Debug] = ;

Modified: trunk/Tools/TestWebKitAPI/PlatformUtilities.h (284976 => 284977)


--- trunk/Tools/TestWebKitAPI/PlatformUtilities.h	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/TestWebKitAPI/PlatformUtilities.h	2021-10-28 15:12:06 UTC (rev 284977)
@@ -47,8 +47,10 @@
 #if USE(FOUNDATION)
 std::string toSTD(NSString *);
 bool jsonMatchesExpectedValues(NSString *jsonString, NSDictionary *expected);
-void waitForConditionWithLogging(std::function<bool()>&&, NSTimeInterval loggingTimeout, NSString *message, ...);
+#ifdef __OBJC__
+void waitForConditionWithLogging(std::function<bool()>&&, NSTimeInterval loggingTimeout, NSString *message, ...) NS_FORMAT_FUNCTION(3, 4);
 #endif
+#endif
 
 #if WK_HAVE_C_SPI
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadAlternateHTMLString.mm (284976 => 284977)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadAlternateHTMLString.mm	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadAlternateHTMLString.mm	2021-10-28 15:12:06 UTC (rev 284977)
@@ -171,7 +171,7 @@
         completionHandler(WKNavigationActionPolicyAllow);
     };
     webView.get().navigationDelegate = delegate.get();
-    NSString *html = @"<script>var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://127.0.0.1:%d/', true); xhr.send();</script>";
+    constexpr NSString *html = @"<script>var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://127.0.0.1:%d/', true); xhr.send();</script>";
     [webView loadHTMLString:[NSString stringWithFormat:html, server.port()] baseURL:[NSURL URLWithString:@"custom-scheme://"]];
     Util::run(&done);
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm (284976 => 284977)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm	2021-10-28 15:12:06 UTC (rev 284977)
@@ -236,7 +236,7 @@
     sharedCheckWindowFeaturesUIDelegate = adoptNS([[CheckWindowFeaturesUIDelegate alloc] init]);
     [webView setUIDelegate:sharedCheckWindowFeaturesUIDelegate.get()];
     [webView configuration].preferences._javascript_CanOpenWindowsAutomatically = YES;
-    NSString *windowOpenFormatString = @"window.open(\"about:blank\", \"_blank\", \"%@\")";
+    constexpr NSString *windowOpenFormatString = @"window.open(\"about:blank\", \"_blank\", \"%@\")";
 
     [webView evaluateJavaScript:@"window.open(\"about:blank\")" completionHandler:nil];
     TestWebKitAPI::Util::run(&isDone);

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerTCPServer.h (284976 => 284977)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerTCPServer.h	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerTCPServer.h	2021-10-28 15:12:06 UTC (rev 284977)
@@ -48,9 +48,24 @@
             respondToRequests(connection, std::exchange(thirdConnection, { }), { });
         }) { }
 
-    NSURLRequest *request() { return requestWithFormat(@"http://127.0.0.1:%d/main.html"); }
-    NSURLRequest *requestWithLocalhost() { return requestWithFormat(@"http://localhost:%d/main.html"); }
-    NSURLRequest *requestWithFragment() { return requestWithFormat(@"http://127.0.0.1:%d/main.html#fragment"); }
+    NSURLRequest *request()
+    {
+        auto url = "" alloc] initWithFormat:@"http://127.0.0.1:%d/main.html", port()]);
+        return requestWithURLString(url.get());
+    }
+
+    NSURLRequest *requestWithLocalhost()
+    {
+        auto url = "" alloc] initWithFormat:@"http://localhost:%d/main.html", port()]);
+        return requestWithURLString(url.get());
+    }
+
+    NSURLRequest *requestWithFragment()
+    {
+        auto url = "" alloc] initWithFormat:@"http://127.0.0.1:%d/main.html#fragment", port()]);
+        return requestWithURLString(url.get());
+    }
+
     size_t userAgentsChecked() const { return m_userAgentsChecked; }
 
 private:
@@ -65,9 +80,9 @@
                 EXPECT_TRUE(strnstr((const char*)request.data(), makeString("User-Agent: ", expectedUserAgent).utf8().data(), request.size()));
                 m_userAgentsChecked++;
             }
-            NSString *format = @"HTTP/1.1 200 OK\r\n"
+            constexpr NSString *format = @"HTTP/1.1 200 OK\r\n"
             "Content-Type: %s\r\n"
-            "Content-Length: %d\r\n\r\n"
+            "Content-Length: %zu\r\n\r\n"
             "%s";
             auto& info = vector[vectorIndex];
             NSString *response = [NSString stringWithFormat:format, info.mimeType, strlen(info.response), info.response];
@@ -77,6 +92,6 @@
         });
     }
 
-    NSURLRequest *requestWithFormat(NSString *format) { return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:format, port()]]]; }
+    NSURLRequest *requestWithURLString(NSString *urlString) { return [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; }
     size_t m_userAgentsChecked { 0 };
 };

Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm (284976 => 284977)


--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2021-10-28 15:12:06 UTC (rev 284977)
@@ -351,21 +351,21 @@
 
 NSURLRequest *HTTPServer::request(const String& path) const
 {
-    NSString *format = nil;
+    const char* scheme = nullptr;
     switch (m_protocol) {
     case Protocol::Http:
-        format = @"http://127.0.0.1:%d%s";
+        scheme = "http";
         break;
     case Protocol::Https:
     case Protocol::HttpsWithLegacyTLS:
     case Protocol::Http2:
-        format = @"https://127.0.0.1:%d%s";
+        scheme = "https";
         break;
     case Protocol::HttpsProxy:
     case Protocol::HttpsProxyWithAuthentication:
         RELEASE_ASSERT_NOT_REACHED();
     }
-    return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:format, port(), path.utf8().data()]]];
+    return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%s://127.0.0.1:%d%@", scheme, port(), path.createCFString().get()]]];
 }
 
 void Connection::receiveBytes(CompletionHandler<void(Vector<uint8_t>&&)>&& completionHandler, size_t minimumSize) const

Modified: trunk/Tools/WebEditingTester/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/WebEditingTester/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/WebEditingTester/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -53,7 +53,7 @@
 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 GCC_WARN_UNDECLARED_SELECTOR = YES;
 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
-WARNING_CFLAGS = -Wall -W -Wno-unused-parameter
+WARNING_CFLAGS = -Wall -W -Wformat=2 -Wno-unused-parameter;
 
 TARGET_MAC_OS_X_VERSION_MAJOR = $(TARGET_MAC_OS_X_VERSION_MAJOR_$(MACOSX_DEPLOYMENT_TARGET:base)$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier));
 TARGET_MAC_OS_X_VERSION_MAJOR_10_13 = 101300;

Modified: trunk/Tools/WebKitTestRunner/Configurations/Base.xcconfig (284976 => 284977)


--- trunk/Tools/WebKitTestRunner/Configurations/Base.xcconfig	2021-10-28 13:52:02 UTC (rev 284976)
+++ trunk/Tools/WebKitTestRunner/Configurations/Base.xcconfig	2021-10-28 15:12:06 UTC (rev 284977)
@@ -70,7 +70,7 @@
 GCC_WARN_UNUSED_VARIABLE = YES
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=arm64*] = NO;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=x86_64] = NO;
-WARNING_CFLAGS = -Wall -W -Wconditional-uninitialized -Wno-unused-parameter -Wundef;
+WARNING_CFLAGS = -Wall -W -Wconditional-uninitialized -Wformat=2 -Wno-unused-parameter -Wundef;
 GCC_PREFIX_HEADER = WebKitTestRunnerPrefix.h
 
 DEBUG_DEFINES = NDEBUG;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to