forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic for catching unsafe scoped_refptr conversions to T* in returns
The tool doesn't attempt to handle all potential unsafe conversions. It only attempts to catch a conservative subset of the conversions that are definitely unsafe, such as returning a local scoped_refptr<T> or temporary. If it encounters something that isn't simple to resolve as safe/unsafe (for example, a reference may be bound to a variable with local storage, which is unsafe, or it may be bound to a member, which is probably safe), it prefers to skip rewriting anything at all, so it can be manually resolved. BUG=110610 R=rsleevi@chromium.org Review URL: https://codereview.chromium.org/472923002 Cr-Commit-Position: refs/heads/master@{#290225} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290225 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
dcheng@chromium.org
committed
Aug 18, 2014
1 parent
97e17d0
commit edb71ee
Showing
7 changed files
with
207 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tools/clang/rewrite_scoped_refptr/tests/ref-to-local-returned-as-raw-expected.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/ref_counted.h" | ||
|
||
struct Foo : public base::RefCounted<Foo> { | ||
int dummy; | ||
}; | ||
|
||
// An example of an unsafe conversion, since the reference is bound to a | ||
// scoped_refptr with local storage. The tool should ignore this, since it | ||
// should prefer letting a human manually resolve trickier cases like this. | ||
Foo* TestFunction() { | ||
scoped_refptr<Foo> a; | ||
scoped_refptr<Foo>& b = a; | ||
return b; | ||
} |
18 changes: 18 additions & 0 deletions
18
tools/clang/rewrite_scoped_refptr/tests/ref-to-local-returned-as-raw-original.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/ref_counted.h" | ||
|
||
struct Foo : public base::RefCounted<Foo> { | ||
int dummy; | ||
}; | ||
|
||
// An example of an unsafe conversion, since the reference is bound to a | ||
// scoped_refptr with local storage. The tool should ignore this, since it | ||
// should prefer letting a human manually resolve trickier cases like this. | ||
Foo* TestFunction() { | ||
scoped_refptr<Foo> a; | ||
scoped_refptr<Foo>& b = a; | ||
return b; | ||
} |
22 changes: 22 additions & 0 deletions
22
tools/clang/rewrite_scoped_refptr/tests/temp-returned-as-raw-expected.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/ref_counted.h" | ||
|
||
struct Foo : public base::RefCounted<Foo> { | ||
int dummy; | ||
}; | ||
|
||
class Bar { | ||
scoped_refptr<Foo> TestFunction(); | ||
}; | ||
|
||
scoped_refptr<Foo> CreateFoo(); | ||
|
||
// An example of an unsafe conversion--the scoped_refptr will be destroyed by | ||
// the time function returns, since it's a temporary, so the returned raw | ||
// pointer may point to a deleted object. | ||
scoped_refptr<Foo> Bar::TestFunction() { | ||
return CreateFoo(); | ||
} |
22 changes: 22 additions & 0 deletions
22
tools/clang/rewrite_scoped_refptr/tests/temp-returned-as-raw-original.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/ref_counted.h" | ||
|
||
struct Foo : public base::RefCounted<Foo> { | ||
int dummy; | ||
}; | ||
|
||
class Bar { | ||
Foo* TestFunction(); | ||
}; | ||
|
||
scoped_refptr<Foo> CreateFoo(); | ||
|
||
// An example of an unsafe conversion--the scoped_refptr will be destroyed by | ||
// the time function returns, since it's a temporary, so the returned raw | ||
// pointer may point to a deleted object. | ||
Foo* Bar::TestFunction() { | ||
return CreateFoo(); | ||
} |