Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Jan 22, 2025
1 parent fc8acca commit 51a73ea
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions fuzz/url_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@
#include "ada.h"

std::string bytesToAlphanumeric(const std::string& source) {
static const char alphanumeric[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
static const char alphanumeric[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";

std::string result;
result.reserve(source.size());
std::string result;
result.reserve(source.size());

for (char byte : source) {
int index = static_cast<unsigned char>(byte) % (sizeof(alphanumeric) - 1);
result.push_back(alphanumeric[index]);
}
for (char byte : source) {
int index = static_cast<unsigned char>(byte) % (sizeof(alphanumeric) - 1);
result.push_back(alphanumeric[index]);
}

return result;
return result;
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider fdp(data, size);
// We do not want to trigger arbitrary regex matching.
std::string source = "/"+ bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
std::string base_source = "/"+ bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
std::string source =
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
std::string base_source =
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));

// Without base or options
auto result = ada::parse_url_pattern(source, nullptr, nullptr);
Expand Down

0 comments on commit 51a73ea

Please sign in to comment.