Commit 68a48f7a authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Fix else-after-return in base

$ ninja -C out/Release base
$ tools/clang/scripts/generate_compdb.py -p out/Release \
  > out/Release/compile_commands.json
$ cd out/Release
$ ~/dev/llvm/llvm/tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \
  -p . -clang-tidy-binary ~/dev/llvm/build/bin/clang-tidy \
  -clang-apply-replacements-binary \
  ~/dev/llvm/build/bin/clang-apply-replacements
  -checks=readability-else-after-return -fix ~/dev/chromium_official/src/base/
$ cd ../..
$ git checkout base/third_party
$ git cl format

R=thestig

Change-Id: Ifc44900f372ed4027027ba50f7a7de22d0e2f0ec
Reviewed-on: https://chromium-review.googlesource.com/1214691
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590385}
parent e02502b4
...@@ -107,9 +107,8 @@ class AllocatorShimTest : public testing::Test { ...@@ -107,9 +107,8 @@ class AllocatorShimTest : public testing::Test {
if (!instance_->did_fail_realloc_0xfeed_once->Get()) { if (!instance_->did_fail_realloc_0xfeed_once->Get()) {
instance_->did_fail_realloc_0xfeed_once->Set(true); instance_->did_fail_realloc_0xfeed_once->Set(true);
return nullptr; return nullptr;
} else {
return address;
} }
return address;
} }
if (size < kMaxSizeTracked) if (size < kMaxSizeTracked)
......
...@@ -276,8 +276,7 @@ void* PartitionReallocGenericFlags(PartitionRootGeneric* root, ...@@ -276,8 +276,7 @@ void* PartitionReallocGenericFlags(PartitionRootGeneric* root,
if (new_size > kGenericMaxDirectMapped) { if (new_size > kGenericMaxDirectMapped) {
if (flags & PartitionAllocReturnNull) if (flags & PartitionAllocReturnNull)
return nullptr; return nullptr;
else internal::PartitionExcessiveAllocationSize();
internal::PartitionExcessiveAllocationSize();
} }
internal::PartitionPage* page = internal::PartitionPage::FromPointer( internal::PartitionPage* page = internal::PartitionPage::FromPointer(
...@@ -320,8 +319,7 @@ void* PartitionReallocGenericFlags(PartitionRootGeneric* root, ...@@ -320,8 +319,7 @@ void* PartitionReallocGenericFlags(PartitionRootGeneric* root,
if (!ret) { if (!ret) {
if (flags & PartitionAllocReturnNull) if (flags & PartitionAllocReturnNull)
return nullptr; return nullptr;
else internal::PartitionExcessiveAllocationSize();
internal::PartitionExcessiveAllocationSize();
} }
size_t copy_size = actual_old_size; size_t copy_size = actual_old_size;
......
...@@ -68,9 +68,8 @@ static int NextSize(int size) { ...@@ -68,9 +68,8 @@ static int NextSize(int size) {
CHECK_EQ(size, power); CHECK_EQ(size, power);
return power + 1; return power + 1;
} else {
return -1;
} }
return -1;
} }
static void TestCalloc(size_t n, size_t s, bool ok) { static void TestCalloc(size_t n, size_t s, bool ok) {
......
...@@ -71,15 +71,16 @@ base::i18n::TextDirection GetCharacterDirection(UChar32 character) { ...@@ -71,15 +71,16 @@ base::i18n::TextDirection GetCharacterDirection(UChar32 character) {
// Now that we have the character, we use ICU in order to query for the // Now that we have the character, we use ICU in order to query for the
// appropriate Unicode BiDi character type. // appropriate Unicode BiDi character type.
int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS);
if ((property == U_RIGHT_TO_LEFT) || switch (property) {
(property == U_RIGHT_TO_LEFT_ARABIC) || case U_RIGHT_TO_LEFT:
(property == U_RIGHT_TO_LEFT_EMBEDDING) || case U_RIGHT_TO_LEFT_ARABIC:
(property == U_RIGHT_TO_LEFT_OVERRIDE)) { case U_RIGHT_TO_LEFT_EMBEDDING:
return base::i18n::RIGHT_TO_LEFT; case U_RIGHT_TO_LEFT_OVERRIDE:
} else if ((property == U_LEFT_TO_RIGHT) || return base::i18n::RIGHT_TO_LEFT;
(property == U_LEFT_TO_RIGHT_EMBEDDING) || case U_LEFT_TO_RIGHT:
(property == U_LEFT_TO_RIGHT_OVERRIDE)) { case U_LEFT_TO_RIGHT_EMBEDDING:
return base::i18n::LEFT_TO_RIGHT; case U_LEFT_TO_RIGHT_OVERRIDE:
return base::i18n::LEFT_TO_RIGHT;
} }
return base::i18n::UNKNOWN_DIRECTION; return base::i18n::UNKNOWN_DIRECTION;
} }
......
...@@ -48,15 +48,13 @@ bool FixedPatternStringSearchIgnoringCaseAndAccents::Search( ...@@ -48,15 +48,13 @@ bool FixedPatternStringSearchIgnoringCaseAndAccents::Search(
// substring search will give the correct return value. // substring search will give the correct return value.
if (!U_SUCCESS(status)) { if (!U_SUCCESS(status)) {
size_t index = in_this.find(find_this_); size_t index = in_this.find(find_this_);
if (index == string16::npos) { if (index == string16::npos)
return false; return false;
} else { if (match_index)
if (match_index) *match_index = index;
*match_index = index; if (match_length)
if (match_length) *match_length = find_this_.size();
*match_length = find_this_.size(); return true;
return true;
}
} }
int32_t index = usearch_first(search_, &status); int32_t index = usearch_first(search_, &status);
......
...@@ -123,9 +123,8 @@ string16 TimeFormatTimeOfDayWithHourClockType(const Time& time, ...@@ -123,9 +123,8 @@ string16 TimeFormatTimeOfDayWithHourClockType(const Time& time,
if (ampm == kKeepAmPm) { if (ampm == kKeepAmPm) {
return TimeFormat(&formatter, time); return TimeFormat(&formatter, time);
} else {
return TimeFormatWithoutAmPm(&formatter, time);
} }
return TimeFormatWithoutAmPm(&formatter, time);
} }
string16 TimeFormatShortDate(const Time& time) { string16 TimeFormatShortDate(const Time& time) {
...@@ -291,11 +290,7 @@ HourClockType GetHourClockType() { ...@@ -291,11 +290,7 @@ HourClockType GetHourClockType() {
// //
// See http://userguide.icu-project.org/formatparse/datetime for details // See http://userguide.icu-project.org/formatparse/datetime for details
// about the date/time format syntax. // about the date/time format syntax.
if (pattern_unicode.indexOf('a') == -1) { return pattern_unicode.indexOf('a') == -1 ? k24HourClock : k12HourClock;
return k24HourClock;
} else {
return k12HourClock;
}
} }
} // namespace base } // namespace base
...@@ -69,10 +69,8 @@ int JSONFileValueDeserializer::ReadFileToString(std::string* json_string) { ...@@ -69,10 +69,8 @@ int JSONFileValueDeserializer::ReadFileToString(std::string* json_string) {
return JSON_ACCESS_DENIED; return JSON_ACCESS_DENIED;
} }
#endif #endif
if (!base::PathExists(json_file_path_)) return base::PathExists(json_file_path_) ? JSON_CANNOT_READ_FILE
return JSON_NO_SUCH_FILE; : JSON_NO_SUCH_FILE;
else
return JSON_CANNOT_READ_FILE;
} }
last_read_size_ = json_string->size(); last_read_size_ = json_string->size();
......
...@@ -471,7 +471,8 @@ bool JSONParser::ConsumeStringRaw(StringBuilder* out) { ...@@ -471,7 +471,8 @@ bool JSONParser::ConsumeStringRaw(StringBuilder* out) {
ConsumeChar(); ConsumeChar();
*out = std::move(string); *out = std::move(string);
return true; return true;
} else if (next_char != '\\') { }
if (next_char != '\\') {
// If this character is not an escape sequence... // If this character is not an escape sequence...
ConsumeChar(); ConsumeChar();
string.Append(next_char); string.Append(next_char);
...@@ -714,16 +715,14 @@ bool JSONParser::ReadInt(bool allow_leading_zeros) { ...@@ -714,16 +715,14 @@ bool JSONParser::ReadInt(bool allow_leading_zeros) {
} }
Optional<Value> JSONParser::ConsumeLiteral() { Optional<Value> JSONParser::ConsumeLiteral() {
if (ConsumeIfMatch("true")) { if (ConsumeIfMatch("true"))
return Value(true); return Value(true);
} else if (ConsumeIfMatch("false")) { if (ConsumeIfMatch("false"))
return Value(false); return Value(false);
} else if (ConsumeIfMatch("null")) { if (ConsumeIfMatch("null"))
return Value(Value::Type::NONE); return Value(Value::Type::NONE);
} else { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1);
ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); return nullopt;
return nullopt;
}
} }
bool JSONParser::ConsumeIfMatch(StringPiece match) { bool JSONParser::ConsumeIfMatch(StringPiece match) {
......
...@@ -34,7 +34,8 @@ struct SimpleMessage { ...@@ -34,7 +34,8 @@ struct SimpleMessage {
if (value == "foo") { if (value == "foo") {
*field = FOO; *field = FOO;
return true; return true;
} else if (value == "bar") { }
if (value == "bar") {
*field = BAR; *field = BAR;
return true; return true;
} }
......
...@@ -169,8 +169,7 @@ std::ostream& operator <<(std::ostream& os, TaskType type) { ...@@ -169,8 +169,7 @@ std::ostream& operator <<(std::ostream& os, TaskType type) {
std::ostream& operator <<(std::ostream& os, const TaskItem& item) { std::ostream& operator <<(std::ostream& os, const TaskItem& item) {
if (item.start) if (item.start)
return os << item.type << " " << item.cookie << " starts"; return os << item.type << " " << item.cookie << " starts";
else return os << item.type << " " << item.cookie << " ends";
return os << item.type << " " << item.cookie << " ends";
} }
class TaskList { class TaskList {
......
...@@ -817,17 +817,15 @@ void PersistentMemoryAllocator::MakeIterable(Reference ref) { ...@@ -817,17 +817,15 @@ void PersistentMemoryAllocator::MakeIterable(Reference ref) {
std::memory_order_release, std::memory_order_release,
std::memory_order_relaxed); std::memory_order_relaxed);
return; return;
} else {
// In the unlikely case that a thread crashed or was killed between the
// update of "next" and the update of "tailptr", it is necessary to
// perform the operation that would have been done. There's no explicit
// check for crash/kill which means that this operation may also happen
// even when the other thread is in perfect working order which is what
// necessitates the CompareAndSwap above.
shared_meta()->tailptr.compare_exchange_strong(tail, next,
std::memory_order_acq_rel,
std::memory_order_acquire);
} }
// In the unlikely case that a thread crashed or was killed between the
// update of "next" and the update of "tailptr", it is necessary to
// perform the operation that would have been done. There's no explicit
// check for crash/kill which means that this operation may also happen
// even when the other thread is in perfect working order which is what
// necessitates the CompareAndSwap above.
shared_meta()->tailptr.compare_exchange_strong(
tail, next, std::memory_order_acq_rel, std::memory_order_acquire);
} }
} }
......
...@@ -36,7 +36,8 @@ TerminationStatus GetTerminationStatusImpl(ProcessHandle handle, ...@@ -36,7 +36,8 @@ TerminationStatus GetTerminationStatusImpl(ProcessHandle handle,
DPLOG(ERROR) << "waitpid(" << handle << ")"; DPLOG(ERROR) << "waitpid(" << handle << ")";
*exit_code = 0; *exit_code = 0;
return TERMINATION_STATUS_NORMAL_TERMINATION; return TERMINATION_STATUS_NORMAL_TERMINATION;
} else if (result == 0) { }
if (result == 0) {
// the child hasn't exited yet. // the child hasn't exited yet.
*exit_code = 0; *exit_code = 0;
return TERMINATION_STATUS_STILL_RUNNING; return TERMINATION_STATUS_STILL_RUNNING;
......
...@@ -376,7 +376,8 @@ Process LaunchProcess(const std::vector<std::string>& argv, ...@@ -376,7 +376,8 @@ Process LaunchProcess(const std::vector<std::string>& argv,
if (pid < 0) { if (pid < 0) {
DPLOG(ERROR) << "fork"; DPLOG(ERROR) << "fork";
return Process(); return Process();
} else if (pid == 0) { }
if (pid == 0) {
// Child process // Child process
// DANGER: no calls to malloc or locks are allowed from now on: // DANGER: no calls to malloc or locks are allowed from now on:
......
...@@ -66,15 +66,13 @@ class SecureHashAlgorithm { ...@@ -66,15 +66,13 @@ class SecureHashAlgorithm {
}; };
static inline uint32_t f(uint32_t t, uint32_t B, uint32_t C, uint32_t D) { static inline uint32_t f(uint32_t t, uint32_t B, uint32_t C, uint32_t D) {
if (t < 20) { if (t < 20)
return (B & C) | ((~B) & D); return (B & C) | ((~B) & D);
} else if (t < 40) { if (t < 40)
return B ^ C ^ D; return B ^ C ^ D;
} else if (t < 60) { if (t < 60)
return (B & C) | (B & D) | (C & D); return (B & C) | (B & D) | (C & D);
} else { return B ^ C ^ D;
return B ^ C ^ D;
}
} }
static inline uint32_t S(uint32_t n, uint32_t X) { static inline uint32_t S(uint32_t n, uint32_t X) {
...@@ -82,15 +80,13 @@ static inline uint32_t S(uint32_t n, uint32_t X) { ...@@ -82,15 +80,13 @@ static inline uint32_t S(uint32_t n, uint32_t X) {
} }
static inline uint32_t K(uint32_t t) { static inline uint32_t K(uint32_t t) {
if (t < 20) { if (t < 20)
return 0x5a827999; return 0x5a827999;
} else if (t < 40) { if (t < 40)
return 0x6ed9eba1; return 0x6ed9eba1;
} else if (t < 60) { if (t < 60)
return 0x8f1bbcdc; return 0x8f1bbcdc;
} else { return 0xca62c1d6;
return 0xca62c1d6;
}
} }
const int SecureHashAlgorithm::kDigestSizeBytes = 20; const int SecureHashAlgorithm::kDigestSizeBytes = 20;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <algorithm>
#include <limits> #include <limits>
#include "base/macros.h" #include "base/macros.h"
...@@ -236,10 +237,9 @@ class Buffer { ...@@ -236,10 +237,9 @@ class Buffer {
if (count_ > kSSizeMax - 1 - inc) { if (count_ > kSSizeMax - 1 - inc) {
count_ = kSSizeMax - 1; count_ = kSSizeMax - 1;
return false; return false;
} else {
count_ += inc;
return true;
} }
count_ += inc;
return true;
} }
// Convenience method for the common case of incrementing |count_| by one. // Convenience method for the common case of incrementing |count_| by one.
...@@ -433,11 +433,9 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args, ...@@ -433,11 +433,9 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
// never overflows kSSizeMax. Not only does that use up most or all of the // never overflows kSSizeMax. Not only does that use up most or all of the
// address space, it also would result in a return code that cannot be // address space, it also would result in a return code that cannot be
// represented. // represented.
if (static_cast<ssize_t>(sz) < 1) { if (static_cast<ssize_t>(sz) < 1)
return -1; return -1;
} else if (sz > kSSizeMax) { sz = std::min(sz, kSSizeMax);
sz = kSSizeMax;
}
// Iterate over format string and interpret '%' arguments as they are // Iterate over format string and interpret '%' arguments as they are
// encountered. // encountered.
...@@ -659,11 +657,9 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt) { ...@@ -659,11 +657,9 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt) {
// never overflows kSSizeMax. Not only does that use up most or all of the // never overflows kSSizeMax. Not only does that use up most or all of the
// address space, it also would result in a return code that cannot be // address space, it also would result in a return code that cannot be
// represented. // represented.
if (static_cast<ssize_t>(sz) < 1) { if (static_cast<ssize_t>(sz) < 1)
return -1; return -1;
} else if (sz > kSSizeMax) { sz = std::min(sz, kSSizeMax);
sz = kSSizeMax;
}
Buffer buffer(buf, sz); Buffer buffer(buf, sz);
......
...@@ -467,13 +467,11 @@ bool Query::GetAsString(const TraceEvent& event, std::string* str) const { ...@@ -467,13 +467,11 @@ bool Query::GetAsString(const TraceEvent& event, std::string* str) const {
const TraceEvent* Query::SelectTargetEvent(const TraceEvent* event, const TraceEvent* Query::SelectTargetEvent(const TraceEvent* event,
TraceEventMember member) { TraceEventMember member) {
if (member >= OTHER_FIRST_MEMBER && member <= OTHER_LAST_MEMBER) { if (member >= OTHER_FIRST_MEMBER && member <= OTHER_LAST_MEMBER)
return event->other_event; return event->other_event;
} else if (member >= PREV_FIRST_MEMBER && member <= PREV_LAST_MEMBER) { if (member >= PREV_FIRST_MEMBER && member <= PREV_LAST_MEMBER)
return event->prev_event; return event->prev_event;
} else { return event;
return event;
}
} }
bool Query::GetMemberValueAsDouble(const TraceEvent& event, bool Query::GetMemberValueAsDouble(const TraceEvent& event,
......
...@@ -106,10 +106,7 @@ typedef time_t SysTime; ...@@ -106,10 +106,7 @@ typedef time_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) { SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
base::AutoLock locked(*GetSysTimeToTimeStructLock()); base::AutoLock locked(*GetSysTimeToTimeStructLock());
if (is_local) return is_local ? mktime(timestruct) : timegm(timestruct);
return mktime(timestruct);
else
return timegm(timestruct);
} }
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) { void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
......
...@@ -33,12 +33,11 @@ int64_t ConvertTimespecToMicros(const struct timespec& ts) { ...@@ -33,12 +33,11 @@ int64_t ConvertTimespecToMicros(const struct timespec& ts) {
result *= base::Time::kMicrosecondsPerSecond; result *= base::Time::kMicrosecondsPerSecond;
result += (ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond); result += (ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond);
return result; return result;
} else {
base::CheckedNumeric<int64_t> result(ts.tv_sec);
result *= base::Time::kMicrosecondsPerSecond;
result += (ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond);
return result.ValueOrDie();
} }
base::CheckedNumeric<int64_t> result(ts.tv_sec);
result *= base::Time::kMicrosecondsPerSecond;
result += (ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond);
return result.ValueOrDie();
} }
// Helper function to get results from clock_gettime() and convert to a // Helper function to get results from clock_gettime() and convert to a
......
...@@ -486,7 +486,8 @@ bool Value::GetAsDouble(double* out_value) const { ...@@ -486,7 +486,8 @@ bool Value::GetAsDouble(double* out_value) const {
if (out_value && is_double()) { if (out_value && is_double()) {
*out_value = double_value_; *out_value = double_value_;
return true; return true;
} else if (out_value && is_int()) { }
if (out_value && is_int()) {
// Allow promotion from int to double. // Allow promotion from int to double.
*out_value = int_value_; *out_value = int_value_;
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment