--- 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