contrib/fuzz/fuzzutil.cc
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 01 Feb 2019 22:52:09 -0800
changeset 41577 5f827e9ce870
parent 38232 a1c0873a9990
permissions -rw-r--r--
status: if ui.relative-paths=no, don't use relative paths even with patterns Without ui.relative-paths or command.status.relative set, you get this behavior: hgext$ hg st M hgext/narrow/narrowrepo.py hgext$ hg st . M narrow/narrowrepo.py hgext$ hg st narrow M narrow/narrowrepo.py I think it's surprising that some of those produce relative paths. I suspect it works that way because "hg st ." was an easy way of getting relative paths. Perhaps not much thought was given to how it should behave when the pattern was not ".". It also feels wrong to conflate the request for relative patterns with matching of of patterns. Since we can now start fresh and define the behavior of ui.relative-paths as we want, I suggest we make ui.relative-paths=no consistently not give relative paths. So that's what this paths starts doing for `hg status`. Differential Revision: https://phab.mercurial-scm.org/D5802
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
#include "fuzzutil.h"
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
38232
a1c0873a9990 fuzz: fix use of undeclared function memcpy()
Yuya Nishihara <yuya@tcha.org>
parents: 38174
diff changeset
     3
#include <cstring>
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#include <utility>
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
38174
36d55f90e2a3 fuzzutil: make it possible to use absl when C++17 isn't supported
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
     6
contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size)
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
{
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
	if (!Size) {
38174
36d55f90e2a3 fuzzutil: make it possible to use absl when C++17 isn't supported
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
     9
		return contrib::nullopt;
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
	}
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
	// figure out a random point in [0, Size] to split our input.
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
	size_t left_size = (Data[0] / 255.0) * (Size - 1);
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
	// Copy inputs to new allocations so if bdiff over-reads
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
	// AddressSanitizer can detect it.
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
	std::unique_ptr<char[]> left(new char[left_size]);
38232
a1c0873a9990 fuzz: fix use of undeclared function memcpy()
Yuya Nishihara <yuya@tcha.org>
parents: 38174
diff changeset
    17
	std::memcpy(left.get(), Data + 1, left_size);
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
	// right starts at the next byte after left ends
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
	size_t right_size = Size - (left_size + 1);
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
	std::unique_ptr<char[]> right(new char[right_size]);
38232
a1c0873a9990 fuzz: fix use of undeclared function memcpy()
Yuya Nishihara <yuya@tcha.org>
parents: 38174
diff changeset
    21
	std::memcpy(right.get(), Data + 1 + left_size, right_size);
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
	LOG(2) << "inputs are  " << left_size << " and " << right_size
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
	       << " bytes" << std::endl;
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
	two_inputs result = {std::move(right), right_size, std::move(left),
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
	                     left_size};
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
	return result;
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
}