[libc-commits] [PATCH] D82247: [libc] Add fuzz test for strcmp.

Chris Gyurgyik via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 23 04:45:31 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ffe2b24f5c7: [libc] Add fuzz test for strcmp. (authored by cgyurgyik).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82247/new/

https://reviews.llvm.org/D82247

Files:
  libc/fuzzing/string/strcmp_fuzz.cpp


Index: libc/fuzzing/string/strcmp_fuzz.cpp
===================================================================
--- libc/fuzzing/string/strcmp_fuzz.cpp
+++ libc/fuzzing/string/strcmp_fuzz.cpp
@@ -10,7 +10,6 @@
 ///
 //===----------------------------------------------------------------------===//
 #include "src/string/strcmp.h"
-#include <algorithm>
 #include <stdint.h>
 
 extern "C" int LLVMFuzzerTestTwoInputs(const uint8_t *data1, size_t size1,
@@ -25,15 +24,17 @@
   const char *s1 = reinterpret_cast<const char *>(data1);
   const char *s2 = reinterpret_cast<const char *>(data2);
 
-  const size_t minimum_size = std::min(size1, size2);
+  const size_t minimum_size = size1 < size2 ? size1 : size2;
 
   // Iterate through until either the minimum size is hit,
   // a character is the null terminator, or the first set
   // of differed bytes between s1 and s2 are found.
   // No bytes following a null byte should be compared.
   size_t i;
-  for (i = 0; i < minimum_size && s1[i] && s1[i] == s2[i]; ++i)
-    ;
+  for (i = 0; i < minimum_size; ++i) {
+    if (!s1[i] || s1[i] != s2[i])
+      break;
+  }
 
   int expected_result = s1[i] - s2[i];
   int actual_result = __llvm_libc::strcmp(s1, s2);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82247.272679.patch
Type: text/x-patch
Size: 1210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200623/7266db04/attachment-0001.bin>


More information about the libc-commits mailing list