Skip to content

Commit

Permalink
Fixes for re-enabling more MSVC level 4 warnings: misc edition chromi…
Browse files Browse the repository at this point in the history
…um#2

This contains fixes for the following sorts of issues:
* Assignment inside conditional
* Taking the address of a temporary
* Octal escape sequence terminated by decimal number
* Signedness mismatch
* Possibly-uninitialized local variable

This also contains a small number of cleanups to nearby code (e.g. no else after return).

BUG=81439
TEST=none

Review URL: https://codereview.chromium.org/382673002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283967 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pkasting@chromium.org committed Jul 18, 2014
1 parent cf85b9a commit 481c3e8
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 132 deletions.
18 changes: 12 additions & 6 deletions ash/drag_drop/drag_drop_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@ int DragDropController::StartDragAndDrop(

void DragDropController::DragUpdate(aura::Window* target,
const ui::LocatedEvent& event) {
aura::client::DragDropDelegate* delegate = NULL;
int op = ui::DragDropTypes::DRAG_NONE;
if (target != drag_window_) {
if (drag_window_) {
if ((delegate = aura::client::GetDragDropDelegate(drag_window_)))
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(drag_window_);
if (delegate)
delegate->OnDragExited();
if (drag_window_ != drag_source_window_)
drag_window_->RemoveObserver(this);
Expand All @@ -257,7 +258,9 @@ void DragDropController::DragUpdate(aura::Window* target,
// We are already an observer of |drag_source_window_| so no need to add.
if (drag_window_ != drag_source_window_)
drag_window_->AddObserver(this);
if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(drag_window_);
if (delegate) {
ui::DropTargetEvent e(*drag_data_,
event.location(),
event.root_location(),
Expand All @@ -266,7 +269,9 @@ void DragDropController::DragUpdate(aura::Window* target,
delegate->OnDragEntered(e);
}
} else {
if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(drag_window_);
if (delegate) {
ui::DropTargetEvent e(*drag_data_,
event.location(),
event.root_location(),
Expand Down Expand Up @@ -298,7 +303,6 @@ void DragDropController::DragUpdate(aura::Window* target,
void DragDropController::Drop(aura::Window* target,
const ui::LocatedEvent& event) {
ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
aura::client::DragDropDelegate* delegate = NULL;

// We must guarantee that a target gets a OnDragEntered before Drop. WebKit
// depends on not getting a Drop without DragEnter. This behavior is
Expand All @@ -307,7 +311,9 @@ void DragDropController::Drop(aura::Window* target,
DragUpdate(target, event);
DCHECK(target == drag_window_);

if ((delegate = aura::client::GetDragDropDelegate(target))) {
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(target);
if (delegate) {
ui::DropTargetEvent e(
*drag_data_, event.location(), event.root_location(), drag_operation_);
e.set_flags(event.flags());
Expand Down
6 changes: 3 additions & 3 deletions cloud_print/virtual_driver/win/install/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ UINT CALLBACK CabinetCallback(PVOID data,
}

void ReadyDriverDependencies(const base::FilePath& destination) {
base::FilePath destination_copy(destination);
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
// GetCorePrinterDrivers and GetPrinterDriverPackagePath only exist on
// Vista and later. Winspool.drv must be delayloaded so these calls don't
Expand All @@ -221,15 +222,14 @@ void ReadyDriverDependencies(const base::FilePath& destination) {
1, &driver);
GetPrinterDriverPackagePath(NULL, NULL, NULL, driver.szPackageID,
package_path, MAX_PATH, &size);
SetupIterateCabinet(package_path, 0, &CabinetCallback,
&base::FilePath(destination));
SetupIterateCabinet(package_path, 0, &CabinetCallback, &destination_copy);
} else {
// Driver files are in the sp3 cab.
base::FilePath package_path;
PathService::Get(base::DIR_WINDOWS, &package_path);
package_path = package_path.Append(L"Driver Cache\\i386\\sp3.cab");
SetupIterateCabinet(package_path.value().c_str(), 0, &CabinetCallback,
&base::FilePath(destination));
&destination_copy);

// Copy the rest from the driver cache or system dir.
base::FilePath driver_cache_path;
Expand Down
2 changes: 1 addition & 1 deletion crypto/symmetric_key_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static const PBKDF2TestVector kTestVectors[] = {
{
crypto::SymmetricKey::HMAC_SHA1,
"password",
"\0224VxxV4\022", /* 0x1234567878563412 */
"\022" "4VxxV4\022", /* 0x1234567878563412 */
5,
160,
"d1daa78615f287e6a1c8b120d7062a493f98d203",
Expand Down
2 changes: 1 addition & 1 deletion device/bluetooth/bluetooth_socket_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ BluetoothSocketWin::BluetoothSocketWin(
const net::NetLog::Source& source)
: BluetoothSocketNet(ui_task_runner, socket_thread, net_log, source),
supports_rfcomm_(false),
rfcomm_channel_(-1),
rfcomm_channel_(0xFF),
bth_addr_(BTH_ADDR_NULL) {
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/browser/extension_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ void ExtensionPrefs::MigratePermissions(const ExtensionIdList& extension_ids) {
// An extension's granted permissions need to be migrated if the
// full_access bit is present. This bit was always present in the previous
// scheme and is never present now.
bool full_access;
bool full_access = false;
const base::DictionaryValue* ext = GetExtensionPref(*ext_id);
if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access))
continue;
Expand Down Expand Up @@ -1288,7 +1288,7 @@ BlacklistState ExtensionPrefs::GetExtensionBlacklistState(
if (IsExtensionBlacklisted(extension_id))
return BLACKLISTED_MALWARE;
const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id);
int int_value;
int int_value = 0;
if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value))
return static_cast<BlacklistState>(int_value);

Expand Down
4 changes: 2 additions & 2 deletions extensions/common/id_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ base::FilePath MaybeNormalizePath(const base::FilePath& path) {
// comparisons simpler.
base::FilePath::StringType path_str = path.value();
if (path_str.size() >= 2 && path_str[0] >= L'a' && path_str[0] <= L'z' &&
path_str[1] == ':')
path_str[0] += ('A' - 'a');
path_str[1] == L':')
path_str[0] = towupper(path_str[0]);

return base::FilePath(path_str);
#else
Expand Down
72 changes: 37 additions & 35 deletions google_apis/gaia/fake_gaia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,21 +413,18 @@ void FakeGaia::HandleSSO(const HttpRequest& request,

void FakeGaia::HandleAuthToken(const HttpRequest& request,
BasicHttpResponse* http_response) {
std::string grant_type;
std::string refresh_token;
std::string client_id;
std::string scope;
std::string auth_code;
const AccessTokenInfo* token_info = NULL;
GetQueryParameter(request.content, "scope", &scope);

std::string grant_type;
if (!GetQueryParameter(request.content, "grant_type", &grant_type)) {
http_response->set_code(net::HTTP_BAD_REQUEST);
LOG(ERROR) << "No 'grant_type' param in /o/oauth2/token";
return;
}

if (grant_type == "authorization_code") {
std::string auth_code;
if (!GetQueryParameter(request.content, "code", &auth_code) ||
auth_code != merge_session_params_.auth_code) {
http_response->set_code(net::HTTP_BAD_REQUEST);
Expand All @@ -448,26 +445,29 @@ void FakeGaia::HandleAuthToken(const HttpRequest& request,
merge_session_params_.access_token);
response_dict.SetInteger("expires_in", 3600);
FormatJSONResponse(response_dict, http_response);
} else if (GetQueryParameter(request.content,
"refresh_token",
&refresh_token) &&
GetQueryParameter(request.content,
"client_id",
&client_id) &&
(token_info = FindAccessTokenInfo(refresh_token,
client_id,
scope))) {
base::DictionaryValue response_dict;
response_dict.SetString("access_token", token_info->token);
response_dict.SetInteger("expires_in", 3600);
FormatJSONResponse(response_dict, http_response);
} else {
LOG(ERROR) << "Bad request for /o/oauth2/token - "
<< "refresh_token = " << refresh_token
<< ", scope = " << scope
<< ", client_id = " << client_id;
http_response->set_code(net::HTTP_BAD_REQUEST);
return;
}

std::string refresh_token;
std::string client_id;
if (GetQueryParameter(request.content, "refresh_token", &refresh_token) &&
GetQueryParameter(request.content, "client_id", &client_id)) {
const AccessTokenInfo* token_info =
FindAccessTokenInfo(refresh_token, client_id, scope);
if (token_info) {
base::DictionaryValue response_dict;
response_dict.SetString("access_token", token_info->token);
response_dict.SetInteger("expires_in", 3600);
FormatJSONResponse(response_dict, http_response);
return;
}
}

LOG(ERROR) << "Bad request for /o/oauth2/token - "
<< "refresh_token = " << refresh_token
<< ", scope = " << scope
<< ", client_id = " << client_id;
http_response->set_code(net::HTTP_BAD_REQUEST);
}

void FakeGaia::HandleTokenInfo(const HttpRequest& request,
Expand Down Expand Up @@ -507,20 +507,22 @@ void FakeGaia::HandleIssueToken(const HttpRequest& request,
std::string access_token;
std::string scope;
std::string client_id;
const AccessTokenInfo* token_info = NULL;
if (GetAccessToken(request, kAuthHeaderBearer, &access_token) &&
GetQueryParameter(request.content, "scope", &scope) &&
GetQueryParameter(request.content, "client_id", &client_id) &&
(token_info = FindAccessTokenInfo(access_token, client_id, scope))) {
base::DictionaryValue response_dict;
response_dict.SetString("issueAdvice", "auto");
response_dict.SetString("expiresIn",
base::IntToString(token_info->expires_in));
response_dict.SetString("token", token_info->token);
FormatJSONResponse(response_dict, http_response);
} else {
http_response->set_code(net::HTTP_BAD_REQUEST);
GetQueryParameter(request.content, "client_id", &client_id)) {
const AccessTokenInfo* token_info =
FindAccessTokenInfo(access_token, client_id, scope);
if (token_info) {
base::DictionaryValue response_dict;
response_dict.SetString("issueAdvice", "auto");
response_dict.SetString("expiresIn",
base::IntToString(token_info->expires_in));
response_dict.SetString("token", token_info->token);
FormatJSONResponse(response_dict, http_response);
return;
}
}
http_response->set_code(net::HTTP_BAD_REQUEST);
}

void FakeGaia::HandleListAccounts(const HttpRequest& request,
Expand Down
26 changes: 11 additions & 15 deletions ipc/ipc_message_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,21 +567,17 @@ void ParamTraits<base::File::Info>::Write(Message* m,
bool ParamTraits<base::File::Info>::Read(const Message* m,
PickleIterator* iter,
param_type* p) {
double last_modified;
double last_accessed;
double creation_time;
bool result =
ReadParam(m, iter, &p->size) &&
ReadParam(m, iter, &p->is_directory) &&
ReadParam(m, iter, &last_modified) &&
ReadParam(m, iter, &last_accessed) &&
ReadParam(m, iter, &creation_time);
if (result) {
p->last_modified = base::Time::FromDoubleT(last_modified);
p->last_accessed = base::Time::FromDoubleT(last_accessed);
p->creation_time = base::Time::FromDoubleT(creation_time);
}
return result;
double last_modified, last_accessed, creation_time;
if (!ReadParam(m, iter, &p->size) ||
!ReadParam(m, iter, &p->is_directory) ||
!ReadParam(m, iter, &last_modified) ||
!ReadParam(m, iter, &last_accessed) ||
!ReadParam(m, iter, &creation_time))
return false;
p->last_modified = base::Time::FromDoubleT(last_modified);
p->last_accessed = base::Time::FromDoubleT(last_accessed);
p->creation_time = base::Time::FromDoubleT(creation_time);
return true;
}

void ParamTraits<base::File::Info>::Log(const param_type& p,
Expand Down
2 changes: 1 addition & 1 deletion jingle/glue/thread_wrapper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ TEST_F(ThreadWrapperTest, SendDuringSend) {
}

TEST_F(ThreadWrapperTest, Dispose) {
bool deleted_;
bool deleted_ = false;
thread_->Dispose(new DeletableObject(&deleted_));
EXPECT_FALSE(deleted_);
message_loop_.RunUntilIdle();
Expand Down
6 changes: 3 additions & 3 deletions jingle/glue/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ bool DeserializeP2PCandidate(const std::string& candidate_str,
static_cast<base::DictionaryValue*>(value.get());

std::string ip;
int port;
int port = 0;
std::string type;
std::string protocol;
std::string username;
std::string password;
double preference;
int generation;
double preference = 0;
int generation = 0;

if (!dic_value->GetString("ip", &ip) ||
!dic_value->GetInteger("port", &port) ||
Expand Down
10 changes: 1 addition & 9 deletions skia/ext/pixel_ref_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ class TestDiscardableShader : public SkShader {
CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_);
}

TestDiscardableShader(SkFlattenableReadBuffer& flattenable_buffer) {
SkOrderedReadBuffer& buffer =
static_cast<SkOrderedReadBuffer&>(flattenable_buffer);
SkReader32* reader = buffer.getReader32();

reader->skip(-4);
uint32_t toSkip = reader->readU32();
reader->skip(toSkip);

TestDiscardableShader(SkReadBuffer& buffer) : SkShader(buffer) {
CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_);
}

Expand Down
23 changes: 10 additions & 13 deletions skia/ext/platform_canvas_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkPixelRef.h"

namespace skia {

namespace {

bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) {
// For masking out the alpha values.
static uint32_t alpha_mask =
static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT;
return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask);
}

// Return true if the canvas is filled to canvas_color, and contains a single
// rectangle filled to rect_color. This function ignores the alpha channel,
// since Windows will sometimes clear the alpha channel when drawing, and we
Expand All @@ -37,21 +45,16 @@ bool VerifyRect(const PlatformCanvas& canvas,
const SkBitmap& bitmap = device->accessBitmap(false);
SkAutoLockPixels lock(bitmap);

// For masking out the alpha values.
uint32_t alpha_mask = 0xFF << SK_A32_SHIFT;

for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) {
for (int cur_x = 0; cur_x < bitmap.width(); cur_x++) {
if (cur_x >= x && cur_x < x + w &&
cur_y >= y && cur_y < y + h) {
// Inside the square should be rect_color
if ((*bitmap.getAddr32(cur_x, cur_y) | alpha_mask) !=
(rect_color | alpha_mask))
if (!IsOfColor(bitmap, cur_x, cur_y, rect_color))
return false;
} else {
// Outside the square should be canvas_color
if ((*bitmap.getAddr32(cur_x, cur_y) | alpha_mask) !=
(canvas_color | alpha_mask))
if (!IsOfColor(bitmap, cur_x, cur_y, canvas_color))
return false;
}
}
Expand All @@ -60,12 +63,6 @@ bool VerifyRect(const PlatformCanvas& canvas,
}

#if !defined(OS_MACOSX)
bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) {
// For masking out the alpha values.
static uint32_t alpha_mask = 0xFF << SK_A32_SHIFT;
return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask);
}

// Return true if canvas has something that passes for a rounded-corner
// rectangle. Basically, we're just checking to make sure that the pixels in the
// middle are of rect_color and pixels in the corners are of canvas_color.
Expand Down
4 changes: 2 additions & 2 deletions sql/recovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ bool Recovery::AutoRecoverTable(const char* table_name,
// |rowid_decl| stores the ROWID version of the last INTEGER column
// seen, which is at |rowid_ofs| in |create_column_decls|.
size_t pk_column_count = 0;
size_t rowid_ofs; // Only valid if rowid_decl is set.
size_t rowid_ofs = 0; // Only valid if rowid_decl is set.
std::string rowid_decl; // ROWID version of column |rowid_ofs|.

while (s.Step()) {
Expand All @@ -372,7 +372,7 @@ bool Recovery::AutoRecoverTable(const char* table_name,
// (zero for not in primary key). I find that it is always 1 for
// columns in the primary key. Since this code is very dependent on
// that pragma, review if the implementation changes.
DCHECK_EQ(pk_column, 1);
DCHECK_EQ(1, pk_column);
++pk_column_count;
}

Expand Down
Loading

0 comments on commit 481c3e8

Please sign in to comment.