Title: [281735] trunk/Source/WTF
Revision
281735
Author
[email protected]
Date
2021-08-28 09:48:16 -0700 (Sat, 28 Aug 2021)

Log Message

[WTF] Fix static analyzer warnings about nullptr derefs in StringImpl::copyCharacters() and tryMakeStringFromAdapters()
<https://webkit.org/b/229461>
<rdar://problem/82303279>

Reviewed by Darin Adler.

* wtf/text/StringConcatenate.h:
(WTF::tryMakeStringFromAdapters):
- Add nullptr checks for `buffer` since it makes no sense to
  call stringTypeAdapterAccumulator() with a nullptr argument,
  and it fixes static analyzer warnings about dereferencing
  nullptr.
* wtf/text/StringImpl.h:
(WTF::StringImpl::copyCharacters):
- Add `ASSERT(destination || !numCharacters)` statement to
  describe an invariant when calling this method.  This stops
  the static analyzer from emitting false positive warnings
  about `destination` being nullptr.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (281734 => 281735)


--- trunk/Source/WTF/ChangeLog	2021-08-28 13:15:49 UTC (rev 281734)
+++ trunk/Source/WTF/ChangeLog	2021-08-28 16:48:16 UTC (rev 281735)
@@ -1,3 +1,24 @@
+2021-08-28  David Kilzer  <[email protected]>
+
+        [WTF] Fix static analyzer warnings about nullptr derefs in StringImpl::copyCharacters() and tryMakeStringFromAdapters()
+        <https://webkit.org/b/229461>
+        <rdar://problem/82303279>
+
+        Reviewed by Darin Adler.
+
+        * wtf/text/StringConcatenate.h:
+        (WTF::tryMakeStringFromAdapters):
+        - Add nullptr checks for `buffer` since it makes no sense to
+          call stringTypeAdapterAccumulator() with a nullptr argument,
+          and it fixes static analyzer warnings about dereferencing
+          nullptr.
+        * wtf/text/StringImpl.h:
+        (WTF::StringImpl::copyCharacters):
+        - Add `ASSERT(destination || !numCharacters)` statement to
+          describe an invariant when calling this method.  This stops
+          the static analyzer from emitting false positive warnings
+          about `destination` being nullptr.
+
 2021-08-27  Simon Fraser  <[email protected]>
 
         Define ENABLE_CONTENT_CHANGE_OBSERVER for IOS_FAMILY and use it to wrap content observation code

Modified: trunk/Source/WTF/wtf/text/StringConcatenate.h (281734 => 281735)


--- trunk/Source/WTF/wtf/text/StringConcatenate.h	2021-08-28 13:15:49 UTC (rev 281734)
+++ trunk/Source/WTF/wtf/text/StringConcatenate.h	2021-08-28 16:48:16 UTC (rev 281735)
@@ -442,7 +442,8 @@
         if (!resultImpl)
             return String();
 
-        stringTypeAdapterAccumulator(buffer, adapter, adapters...);
+        if (buffer)
+            stringTypeAdapterAccumulator(buffer, adapter, adapters...);
 
         return resultImpl;
     }
@@ -452,7 +453,8 @@
     if (!resultImpl)
         return String();
 
-    stringTypeAdapterAccumulator(buffer, adapter, adapters...);
+    if (buffer)
+        stringTypeAdapterAccumulator(buffer, adapter, adapters...);
 
     return resultImpl;
 }

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (281734 => 281735)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2021-08-28 13:15:49 UTC (rev 281734)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2021-08-28 16:48:16 UTC (rev 281735)
@@ -1125,6 +1125,7 @@
 template<typename SourceCharacterType, typename DestinationCharacterType>
 inline void StringImpl::copyCharacters(DestinationCharacterType* destination, const SourceCharacterType* source, unsigned numCharacters)
 {
+    ASSERT(destination || !numCharacters); // Workaround for clang static analyzer (<rdar://problem/82475719>).
     static_assert(std::is_same_v<SourceCharacterType, LChar> || std::is_same_v<SourceCharacterType, UChar>);
     static_assert(std::is_same_v<DestinationCharacterType, LChar> || std::is_same_v<DestinationCharacterType, UChar>);
     if constexpr (std::is_same_v<SourceCharacterType, DestinationCharacterType>) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to