Skip to content
This repository has been archived by the owner. It is now read-only.

make cpp lint happy across the board #182

Merged
merged 1 commit into from Feb 27, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

make cpp lint happy across the board

  • Loading branch information
pes10k committed Feb 26, 2019
commit 67e2327dfc18daaa961383bf0ec09c501f1d7aab
@@ -859,7 +859,7 @@ bool AdBlockClient::matches(const char* input, FilterOption contextOption,

if (isNoFingerprintDomainHashSetMiss(
noFingerprintAntiDomainExceptionHashSet, contextDomain,
contextDomainLen )) {
contextDomainLen)) {
hasExceptionMatch = hasExceptionMatch ||
hasMatchingFilters(noFingerprintAntiDomainOnlyExceptionFilters,
numNoFingerprintAntiDomainOnlyExceptionFilters, input, inputLen,
@@ -1243,7 +1243,6 @@ bool AdBlockClient::parse(const char *input, bool preserveRules) {
noFingerprintDomainOnlyExceptionFilters ||
noFingerprintAntiDomainOnlyFilters ||
noFingerprintAntiDomainOnlyExceptionFilters) {

// Copy the old data in, we can't simply use memcpy here
// since filtres manages some pointers that get deleted.
for (int i = 0; i < numFilters; i++) {
@@ -1262,19 +1261,24 @@ bool AdBlockClient::parse(const char *input, bool preserveRules) {
newNoFingerprintFilters[i].swapData(&(noFingerprintFilters[i]));
}
for (int i = 0; i < numNoFingerprintExceptionFilters; i++) {
newNoFingerprintExceptionFilters[i].swapData(&(noFingerprintExceptionFilters[i]));
newNoFingerprintExceptionFilters[i].swapData(
&(noFingerprintExceptionFilters[i]));
}
for (int i = 0; i < numNoFingerprintDomainOnlyFilters; i++) {
newNoFingerprintDomainOnlyFilters[i].swapData(&(noFingerprintDomainOnlyFilters[i]));
newNoFingerprintDomainOnlyFilters[i].swapData(
&(noFingerprintDomainOnlyFilters[i]));
}
for (int i = 0; i < numNoFingerprintAntiDomainOnlyFilters; i++) {
newNoFingerprintAntiDomainOnlyFilters[i].swapData(&(noFingerprintAntiDomainOnlyFilters[i]));
newNoFingerprintAntiDomainOnlyFilters[i].swapData(
&(noFingerprintAntiDomainOnlyFilters[i]));
}
for (int i = 0; i < numNoFingerprintDomainOnlyExceptionFilters; i++) {
newNoFingerprintDomainOnlyExceptionFilters[i].swapData(&(noFingerprintDomainOnlyExceptionFilters[i]));
newNoFingerprintDomainOnlyExceptionFilters[i].swapData(
&(noFingerprintDomainOnlyExceptionFilters[i]));
}
for (int i = 0; i < numNoFingerprintAntiDomainOnlyExceptionFilters; i++) {
newNoFingerprintAntiDomainOnlyExceptionFilters[i].swapData(&(noFingerprintAntiDomainOnlyExceptionFilters[i]));
newNoFingerprintAntiDomainOnlyExceptionFilters[i].swapData(
&(noFingerprintAntiDomainOnlyExceptionFilters[i]));
}

// Free up the old memory for filter storage
@@ -84,10 +84,12 @@ void GenerateManifestFile(const std::string &name,
std::ofstream outFile(filename);
if (outFile.is_open()) {
outFile << "{" << std::endl;
outFile << " \"description\": \"Brave Ad Block Updater extension\"," << std::endl;
outFile << " \"description\": \"Brave Ad Block Updater extension\","
<< std::endl;
outFile << " \"key\": \"" << base64_public_key << "\"," << std::endl;
outFile << " \"manifest_version\": 2," << std::endl;
outFile << " \"name\": \"Brave Ad Block Updater (" << name << ")\"," << std::endl;
outFile << " \"name\": \"Brave Ad Block Updater (" << name << ")\","
<< std::endl;
outFile << " \"version\": \"0.0.0\"" << std::endl;
outFile << "}" << std::endl;
}
@@ -326,7 +328,8 @@ void AdBlockClientWrap::Deserialize(const FunctionCallbackInfo<Value>& args) {

if (!args[0]->IsArrayBufferView()) {
isolate->ThrowException(v8::Exception::Error(
String::NewFromUtf8(isolate, "Provided string is not valid, serialized DAT data")));
String::NewFromUtf8(isolate,
"Provided string is not valid, serialized DAT data")));
return;
}

@@ -578,7 +581,11 @@ void AdBlockClientWrap::GenerateRegionalManifestFiles(
String::Utf8Value str(isolate, args[0]->ToString());
const char * dir = *str;
for (auto& entry : region_lists) {
std::string filename = dir + std::string("/") + entry.uuid + std::string("-manifest.json");
const std::string filename = (
dir +
std::string("/") +
entry.uuid +
std::string("-manifest.json"));
GenerateManifestFile(entry.title, entry.base64_public_key, filename);
}
}
@@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "context_domain.h"
#include "./context_domain.h"
#include "hashFn.h"

static HashFn context_domain_hash(19);
@@ -7,7 +7,7 @@
#define CONTEXT_DOMAIN_H_

#include <string.h>
#include "base.h"
#include "./base.h"

// This class must operate off of borrowed memory
// Serialization and deserialization is not supported intentionally.
@@ -3,23 +3,20 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "./filter.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <set>
#include <string>

#ifdef ENABLE_REGEX
#include <regex> // NOLINT
#endif

#include "./filter.h"
#include "hashFn.h"
#include "./hash_set.h"
#include "./ad_block_client.h"

#include "hashFn.h"
#include "BloomFilter.h"
#include "hash_set.h"

static HashFn h(19);

@@ -374,10 +371,11 @@ bool Filter::contextDomainMatchesFilter(const char *contextDomain) {
size_t contextDomainLen = strlen(contextDomain);
while (*p != '\0') {
if (*p == '.') {
if (containsDomain(start, contextDomainLen - (start - contextDomain), false)) {
const size_t domainLen = contextDomainLen - (start - contextDomain);
if (containsDomain(start, domainLen, false)) {
return true;
}
if (containsDomain(start, contextDomainLen - (start - contextDomain), true)) {
if (containsDomain(start, domainLen, true)) {
return false;
}
// Set start to just past the period
@@ -77,7 +77,8 @@ enum FilterOption {
FOResourcesOnly = FOScript|FOImage|FOStylesheet|FOObject|FOXmlHttpRequest|
FOObjectSubrequest|FOSubdocument|FODocument|FOOther|FOXBL|FOFont|FOMedia|
FOWebRTC|FOWebsocket|FOPing,
FOUnsupportedSoSkipCheck = FOPopup|FOCSP|FOElemHide|FOGenericHide|FOGenericBlock|FOEmpty|FOUnknown,
FOUnsupportedSoSkipCheck = FOPopup|FOCSP|FOElemHide|FOGenericHide|
FOGenericBlock|FOEmpty|FOUnknown,
FOUnsupportedButIgnore = FORedirect|FOImportant
};

@@ -0,0 +1 @@
linelength = 10000
@@ -7,9 +7,10 @@
#define LISTS_DEFAULT_H_

#include <vector>
#include <string>
#include "../filter_list.h"

const std::string kAdBlockDefaultComponentId("cffkpbalmllkdoenhmdmpbkajipdjfam");
const std::string kAdBlockDefaultComponentId("cffkpbalmllkdoenhmdmpbkajipdjfam"); // NOLINT
const std::string kAdBlockDefaultBase64PublicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs0qzJmHSgIiw7IGFCxij"
"1NnB5hJ5ZQ1LKW9htL4EBOaMJvmqaDs/wfq0nw/goBHWsqqkMBynRTu2Hxxirvdb"
@@ -6,13 +6,6 @@
#include <ctype.h>
#include "./protocol.h"

// Macro for telling -Wimplicit-fallthrough that a fallthrough is intentional.
#if defined(__clang__)
#define FALLTHROUGH [[clang::fallthrough]]
#else
#define FALLTHROUGH
#endif

enum ProtocolParseState {
ProtocolParseStateStart,
ProtocolParseStateReadingBlob,
@@ -61,7 +54,7 @@ bool isBlockableProtocol(const char *url, int urlLen) {
continue;
}
// Intentional fall through
FALLTHROUGH;
[[fallthrough]];
case ProtocolParseStatePostBlob:
lowerChar = tolower(*curChar);
if (lowerChar == 'w') {
@@ -119,7 +112,7 @@ bool isBlockableProtocol(const char *url, int urlLen) {
numCharsReadInState = 1;
break;
}
FALLTHROUGH;
[[fallthrough]];
// Intentional fall through
case ProtocolParseStateReadingSeperator:
if (*curChar == ':' &&
@@ -16,6 +16,8 @@
#include "./ad_block_client.h"
#include "./util.h"

#define CHECK_EQ(a, b) CHECK((a) == (b));

using std::cout;

TEST(ruleDefinition, basic) {
@@ -48,9 +50,9 @@ TEST(ruleDefinition, basic) {
CHECK(client.findMatchingFilters(urlToCheck, FONoFilterOption,
currentPageDomain, &matchingFilter, &matchingExceptionFilter));
CHECK(matchingFilter);
CHECK(strcmp(matchingFilter->data, "&view=ad&") == 0);
CHECK(matchingExceptionFilter == nullptr);
CHECK(strcmp(matchingFilter->ruleDefinition, "&view=ad&") == 0);
CHECK_EQ(strcmp(matchingFilter->data, "&view=ad&"), 0);
CHECK_EQ(matchingExceptionFilter, nullptr);
CHECK_EQ(strcmp(matchingFilter->ruleDefinition, "&view=ad&"), 0);
}

TEST(ruleDefinitionEmptyByDefault, basic) {
@@ -73,9 +75,9 @@ TEST(ruleDefinitionEmptyByDefault, basic) {
CHECK(client.findMatchingFilters(urlToCheck, FOScript, currentPageDomain,
&matchingFilter, &matchingExceptionFilter));
CHECK(matchingFilter);
CHECK(strcmp(matchingFilter->data, "-google-analytics.") == 0);
CHECK(matchingExceptionFilter == nullptr);
CHECK(matchingFilter->ruleDefinition == nullptr);
CHECK_EQ(strcmp(matchingFilter->data, "-google-analytics."), 0);
CHECK_EQ(matchingExceptionFilter, nullptr);
CHECK_EQ(matchingFilter->ruleDefinition, nullptr);
}

// Test to see if we can parse and restore lines correctly, when there is white
@@ -103,9 +105,9 @@ TEST(ruleDefinitionLeadingWhitespace, basic) {
CHECK(client.findMatchingFilters(urlToCheck, FONoFilterOption,
currentPageDomain, &matchingFilter, &matchingExceptionFilter));
CHECK(matchingFilter);
CHECK(strcmp(matchingFilter->data, "&view=ad&") == 0);
CHECK(matchingExceptionFilter == nullptr);
CHECK(strcmp(matchingFilter->ruleDefinition, "&view=ad&") == 0);
CHECK_EQ(strcmp(matchingFilter->data, "&view=ad&"), 0);
CHECK_EQ(matchingExceptionFilter, nullptr);
CHECK_EQ(strcmp(matchingFilter->ruleDefinition, "&view=ad&"), 0);
}


@@ -132,12 +134,9 @@ TEST(ruleDefinitionWithOptions, basic) {
CHECK(client.findMatchingFilters(urlToCheck, FOScript, currentPageDomain,
&matchingFilter, &matchingExceptionFilter));
CHECK(matchingFilter);
CHECK(strcmp(matchingFilter->data, "-google-analytics.") == 0);
CHECK(matchingExceptionFilter == nullptr);
CHECK(
strcmp(
matchingFilter->ruleDefinition,
"-google-analytics.$image,script,xmlhttprequest"
) == 0
);
CHECK_EQ(strcmp(matchingFilter->data, "-google-analytics."), 0);
CHECK_EQ(matchingExceptionFilter, nullptr);
CHECK_EQ(strcmp(
matchingFilter->ruleDefinition,
"-google-analytics.$image,script,xmlhttprequest"), 0);
}
@@ -52,7 +52,9 @@ bool testFilter(const char *rawFilter, FilterType expectedFilterType,
string lastChecked;
std::for_each(blocked.begin(), blocked.end(),
[&filter, &ret, &lastChecked, &expectedFilterOption](string const &s) {
ret = ret && filter.matches(s.c_str(), (FilterOption)(expectedFilterOption & FOResourcesOnly));
const FilterOption filterOptions = static_cast<FilterOption>(
expectedFilterOption & FOResourcesOnly);
ret = ret && filter.matches(s.c_str(), filterOptions);
lastChecked = s;
});
if (!ret) {
@@ -62,7 +64,9 @@ bool testFilter(const char *rawFilter, FilterType expectedFilterType,

std::for_each(notBlocked.begin(), notBlocked.end(),
[&filter, &ret, &lastChecked, &expectedFilterOption](string const &s) {
ret = ret && !filter.matches(s.c_str(), (FilterOption)(expectedFilterOption & FOResourcesOnly));
const auto filterOptions = static_cast<FilterOption>(
expectedFilterOption & FOResourcesOnly);
ret = ret && !filter.matches(s.c_str(), filterOptions);
lastChecked = s;
});
if (!ret) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.