|
|
Created:
5 years, 8 months ago by Reilly Grant (use Gerrit) Modified:
5 years, 8 months ago Reviewers:
benwells CC:
chromium-reviews, chromium-apps-reviews_chromium.org, tfarina, extensions-reviews_chromium.org Base URL:
https://chromium.googlesource.com/chromium/src.git@master Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionInitialize observer_ to nullptr in DevicePermissionsDialogView.
I noticed while doing some refactoring elsewhere that observer_ was not
being initialized and so early calls to OnDevicesChanged could branch on
an uninitialized value and crash.
Committed: https://crrev.com/b61a9fd6fe1a1a61733b0f08e9f1a209c557ec9d
Cr-Commit-Position: refs/heads/master@{#324338}
Patch Set 1 #
Total comments: 4
Messages
Total messages: 11 (2 generated)
reillyg@chromium.org changed reviewers: + benwells@chromium.org
Trivial patch. Please take a look.
https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... File chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc (right): https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc:47: ui::TableModelObserver* observer_ = nullptr; since you already have an initializer list in the constructor, why not do it there, the old fashioned way?
https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... File chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc (right): https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc:47: ui::TableModelObserver* observer_ = nullptr; On 2015/04/08 22:53:22, benwells wrote: > since you already have an initializer list in the constructor, why not do it > there, the old fashioned way? This method guarantees that any future constructor will also inherit this default behavior. Disregarding the initializer list in the constructor this feels equivalent to the way that the scoped_refptr above would be initialized to nullptr because that's what its default constructor does. This is simply working around the lack of a default constructor for raw pointer types.
https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... File chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc (right): https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc:47: ui::TableModelObserver* observer_ = nullptr; On 2015/04/08 22:57:25, reillyg wrote: > On 2015/04/08 22:53:22, benwells wrote: > > since you already have an initializer list in the constructor, why not do it > > there, the old fashioned way? > > This method guarantees that any future constructor will also inherit this > default behavior. Disregarding the initializer list in the constructor this > feels equivalent to the way that the scoped_refptr above would be initialized to > nullptr because that's what its default constructor does. This is simply working > around the lack of a default constructor for raw pointer types. Yes, I understand that this will be caught by all future constructors. Can you see that it might be confusing for people reading the code?
https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... File chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc (right): https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc:47: ui::TableModelObserver* observer_ = nullptr; On 2015/04/08 23:44:29, benwells wrote: > On 2015/04/08 22:57:25, reillyg wrote: > > On 2015/04/08 22:53:22, benwells wrote: > > > since you already have an initializer list in the constructor, why not do it > > > there, the old fashioned way? > > > > This method guarantees that any future constructor will also inherit this > > default behavior. Disregarding the initializer list in the constructor this > > feels equivalent to the way that the scoped_refptr above would be initialized > to > > nullptr because that's what its default constructor does. This is simply > working > > around the lack of a default constructor for raw pointer types. > > Yes, I understand that this will be caught by all future constructors. > > Can you see that it might be confusing for people reading the code? I disagree that this is confusing. This method is clearer than constructor initialization lists because one can tell from reading only the field declarations that they will all be initialized without having to check that the (possibly multiple) constructors aren't missing something. From personal experience I am very likely to shoot myself in the foot by adding a primitive type field to a class and forgetting to add an initializer to the constructor. Combining these two in one place seems like a net win.
On 2015/04/09 00:06:36, reillyg wrote: > https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... > File chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc > (right): > > https://codereview.chromium.org/1075593003/diff/1/chrome/browser/ui/views/ext... > chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc:47: > ui::TableModelObserver* observer_ = nullptr; > On 2015/04/08 23:44:29, benwells wrote: > > On 2015/04/08 22:57:25, reillyg wrote: > > > On 2015/04/08 22:53:22, benwells wrote: > > > > since you already have an initializer list in the constructor, why not do > it > > > > there, the old fashioned way? > > > > > > This method guarantees that any future constructor will also inherit this > > > default behavior. Disregarding the initializer list in the constructor this > > > feels equivalent to the way that the scoped_refptr above would be > initialized > > to > > > nullptr because that's what its default constructor does. This is simply > > working > > > around the lack of a default constructor for raw pointer types. > > > > Yes, I understand that this will be caught by all future constructors. > > > > Can you see that it might be confusing for people reading the code? > > I disagree that this is confusing. This method is clearer than constructor > initialization lists because one can tell from reading only the field > declarations that they will all be initialized without having to check that the > (possibly multiple) constructors aren't missing something. > > From personal experience I am very likely to shoot myself in the foot by adding > a primitive type field to a class and forgetting to add an initializer to the > constructor. Combining these two in one place seems like a net win. It's confusing because it is rare in our codebase. But, it sounds like you've considered all of this which is really what I was wondering. I don't think it matters that much or is worth arguing over, so lgtm.
The CQ bit was checked by reillyg@chromium.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1075593003/1
Message was sent while issue was closed.
Committed patchset #1 (id:1)
Message was sent while issue was closed.
Patchset 1 (id:??) landed as https://crrev.com/b61a9fd6fe1a1a61733b0f08e9f1a209c557ec9d Cr-Commit-Position: refs/heads/master@{#324338} |