Bug 1143575. Avoid use of COMPARE macro which can clash with Android headers. r=bent draft
authorRobert O'Callahan <robert@ocallahan.org>
Sun, 07 Jun 2015 12:26:40 +0300
changeset 275550 cfe55292fe4efda1016d43699e9fbf1e8388d0ac
parent 275549 8567e4ad05e182b2563ba72ceb8cc2aefe3d9f28
child 275551 645ea390a7ae708011796d7ecf6369bdb1f62df2
push id3189
push userrocallahan@mozilla.com
push dateFri, 03 Jul 2015 11:12:01 +0000
reviewersbent
bugs1143575
milestone42.0a1
Bug 1143575. Avoid use of COMPARE macro which can clash with Android headers. r=bent
xpcom/io/nsPipe3.cpp
--- a/xpcom/io/nsPipe3.cpp
+++ b/xpcom/io/nsPipe3.cpp
@@ -1372,20 +1372,22 @@ nsPipeInputStream::Tell(int64_t* aOffset
 
 NS_IMETHODIMP
 nsPipeInputStream::SetEOF()
 {
   NS_NOTREACHED("nsPipeInputStream::SetEOF");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-#define COMPARE(s1, s2, i)                                               \
-  (aIgnoreCase                                                           \
-   ? nsCRT::strncasecmp((const char *)s1, (const char *)s2, (uint32_t)i) \
-   : nsCRT::strncmp((const char *)s1, (const char *)s2, (uint32_t)i))
+static bool strings_equal(bool aIgnoreCase,
+                          const char* aS1, const char* aS2, uint32_t aLen)
+{
+  return aIgnoreCase
+    ? !nsCRT::strncasecmp(aS1, aS2, aLen) : !nsCRT::strncmp(aS1, aS2, aLen);
+}
 
 NS_IMETHODIMP
 nsPipeInputStream::Search(const char* aForString,
                           bool aIgnoreCase,
                           bool* aFound,
                           uint32_t* aOffsetSearchedTo)
 {
   LOG(("III Search [for=%s ic=%u]\n", aForString, aIgnoreCase));
@@ -1405,17 +1407,17 @@ nsPipeInputStream::Search(const char* aF
     return NS_OK;
   }
 
   while (true) {
     uint32_t i, len1 = limit1 - cursor1;
 
     // check if the string is in the buffer segment
     for (i = 0; i < len1 - strLen + 1; i++) {
-      if (COMPARE(&cursor1[i], aForString, strLen) == 0) {
+      if (strings_equal(aIgnoreCase, &cursor1[i], aForString, strLen)) {
         *aFound = true;
         *aOffsetSearchedTo = offset + i;
         LOG(("  result [aFound=%u offset=%u]\n", *aFound, *aOffsetSearchedTo));
         return NS_OK;
       }
     }
 
     // get the next segment
@@ -1437,18 +1439,18 @@ nsPipeInputStream::Search(const char* aF
 
     // check if the string is straddling the next buffer segment
     uint32_t lim = XPCOM_MIN(strLen, len2 + 1);
     for (i = 0; i < lim; ++i) {
       uint32_t strPart1Len = strLen - i - 1;
       uint32_t strPart2Len = strLen - strPart1Len;
       const char* strPart2 = &aForString[strLen - strPart2Len];
       uint32_t bufSeg1Offset = len1 - strPart1Len;
-      if (COMPARE(&cursor1[bufSeg1Offset], aForString, strPart1Len) == 0 &&
-          COMPARE(cursor2, strPart2, strPart2Len) == 0) {
+      if (strings_equal(aIgnoreCase, &cursor1[bufSeg1Offset], aForString, strPart1Len) &&
+          strings_equal(aIgnoreCase, cursor2, strPart2, strPart2Len)) {
         *aFound = true;
         *aOffsetSearchedTo = offset - strPart1Len;
         LOG(("  result [aFound=%u offset=%u]\n", *aFound, *aOffsetSearchedTo));
         return NS_OK;
       }
     }
 
     // finally continue with the next buffer