diff --git a/arcanist/linter/IncludeGuardLinter.php b/arcanist/linter/IncludeGuardLinter.php index c9f0aae5e..849157552 100644 --- a/arcanist/linter/IncludeGuardLinter.php +++ b/arcanist/linter/IncludeGuardLinter.php @@ -1,71 +1,72 @@ ArcanistLintSeverity::SEVERITY_ERROR, ); } public function getLintNameMap() { return array( self::INCLUDE_GUARD_INVALID => pht('Include guard malformed or missing.'), ); } public function lintPath($path) { $abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); $fileContent = Filesystem::readFile($abspath); $pathInfo = pathinfo($path); // Get the path components. They are relative to project root. $guard = explode('/', $pathInfo['dirname']); // Add the file name (without extension) to the path components. $guard[] = $pathInfo['filename']; // Skip the upper 'src' directory $guard = array_slice($guard, 1); // Join to a string using an underscore ('_') as the delimiter. $guard = implode('_', $guard); // Transform the whole string to uppercase. $guard = strtoupper($guard); // Surround with prefix and suffix. $guard = self::GUARD_PREFIX.$guard.self::GUARD_SUFFIX; - if (preg_match_all('/#(?:ifndef|define) '.$guard.'/', $fileContent) != 2) { + if (preg_match_all('@#(?:ifndef|define|endif //) '.$guard.'@', + $fileContent) != 3) { return $this->raiseLintAtPath( self::INCLUDE_GUARD_INVALID, pht("Include guard is malformed or missing. Expected format:\n". "\t#ifndef %s\n". "\t#define %s\n". "\t...\n". "\t#endif // %s", $guard, $guard, $guard)); } } } diff --git a/src/amount.h b/src/amount.h index 8abe957ee..0400a4c6d 100644 --- a/src/amount.h +++ b/src/amount.h @@ -1,173 +1,173 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Copyright (c) 2017-2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_AMOUNT_H #define BITCOIN_AMOUNT_H #include #include #include #include #include struct Amount { private: int64_t amount; explicit constexpr Amount(int64_t _amount) : amount(_amount) {} public: constexpr Amount() : amount(0) {} constexpr Amount(const Amount &other) : amount(other.amount) {} /** * Assignement operator. */ constexpr Amount &operator=(const Amount &other) { amount = other.amount; return *this; } static constexpr Amount zero() { return Amount(0); } static constexpr Amount satoshi() { return Amount(1); } /** * Implement standard operators */ Amount &operator+=(const Amount a) { amount += a.amount; return *this; } Amount &operator-=(const Amount a) { amount -= a.amount; return *this; } /** * Equality */ friend constexpr bool operator==(const Amount a, const Amount b) { return a.amount == b.amount; } friend constexpr bool operator!=(const Amount a, const Amount b) { return !(a == b); } /** * Comparison */ friend constexpr bool operator<(const Amount a, const Amount b) { return a.amount < b.amount; } friend constexpr bool operator>(const Amount a, const Amount b) { return b < a; } friend constexpr bool operator<=(const Amount a, const Amount b) { return !(a > b); } friend constexpr bool operator>=(const Amount a, const Amount b) { return !(a < b); } /** * Unary minus */ constexpr Amount operator-() const { return Amount(-amount); } /** * Addition and subtraction. */ friend constexpr Amount operator+(const Amount a, const Amount b) { return Amount(a.amount + b.amount); } friend constexpr Amount operator-(const Amount a, const Amount b) { return a + -b; } /** * Multiplication */ friend constexpr Amount operator*(const int64_t a, const Amount b) { return Amount(a * b.amount); } friend constexpr Amount operator*(const int a, const Amount b) { return Amount(a * b.amount); } /** * Division */ constexpr int64_t operator/(const Amount b) const { return amount / b.amount; } constexpr Amount operator/(const int64_t b) const { return Amount(amount / b); } constexpr Amount operator/(const int b) const { return Amount(amount / b); } Amount &operator/=(const int64_t n) { amount /= n; return *this; } /** * Modulus */ constexpr Amount operator%(const Amount b) const { return Amount(amount % b.amount); } constexpr Amount operator%(const int64_t b) const { return Amount(amount % b); } constexpr Amount operator%(const int b) const { return Amount(amount % b); } /** * Do not implement double ops to get an error with double and ensure * casting to integer is explicit. */ friend constexpr Amount operator*(const double a, const Amount b) = delete; constexpr Amount operator/(const double b) const = delete; constexpr Amount operator%(const double b) const = delete; // ostream support friend std::ostream &operator<<(std::ostream &stream, const Amount &ca) { return stream << ca.amount; } std::string ToString() const; // serialization support ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream &s, Operation ser_action) { READWRITE(amount); } }; static constexpr Amount SATOSHI = Amount::satoshi(); static constexpr Amount CASH = 100 * SATOSHI; static constexpr Amount COIN = 100000000 * SATOSHI; static constexpr Amount CENT = COIN / 100; extern const std::string CURRENCY_UNIT; /** * No amount larger than this (in satoshi) is valid. * * Note that this constant is *not* the total money supply, which in Bitcoin * currently happens to be less than 21,000,000 BCH for various reasons, but * rather a sanity check. As this sanity check is used by consensus-critical * validation code, the exact value of the MAX_MONEY constant is consensus * critical; in unusual circumstances like a(nother) overflow bug that allowed * for the creation of coins out of thin air modification could lead to a fork. */ static const Amount MAX_MONEY = 21000000 * COIN; inline bool MoneyRange(const Amount nValue) { return nValue >= Amount::zero() && nValue <= MAX_MONEY; } -#endif // BITCOIN_AMOUNT_H +#endif // BITCOIN_AMOUNT_H diff --git a/src/cashaddrenc.h b/src/cashaddrenc.h index 7b0d715fe..323042962 100644 --- a/src/cashaddrenc.h +++ b/src/cashaddrenc.h @@ -1,32 +1,32 @@ // Copyright (c) 2017 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CASHADDRENC_H #define BITCOIN_CASHADDRENC_H #include