|
|
Chromium Code Reviews|
Created:
4 years, 1 month ago by hans Modified:
4 years, 1 month ago Reviewers:
Zhongyi Shi CC:
chromium-reviews Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionClarify that BlockSizeForFileType can't be called with EXTERNAL FileType
PVS-Studio analysis pointed out that if it were called with such a file
type, that would lead to division by zero in RequiredBlocks.
Also, remove the default: case since the enum is now covered. Clang warns
if the switch doesn't cover all enum values.
BUG=660198
Committed: https://crrev.com/d8c29e03c348bdb7ce8522f22515523de1c20df9
Cr-Commit-Position: refs/heads/master@{#428279}
Patch Set 1 #
Total comments: 5
Patch Set 2 : pacify gcc #Messages
Total messages: 22 (8 generated)
hans@chromium.org changed reviewers: + zhongyi@chromium.org
Please take a look.
Could you update your issue description? It seems inconsistent with the code change to me.
On 2016/10/27 23:13:27, Zhongyi Shi wrote: > Could you update your issue description? It seems inconsistent with the code > change to me. Hmm, how is it inconsistent? My change is doing exactly what the description says I think :-) Adding "case EXTERNAL: NOTREACHED()" spells out that the function can't be called with that file type. Since there are no other file types possible, there is no need for the default:. I guess "and cover the enum" should be "because the enum is now covered" though. I'll change that.
Description was changed from ========== Clarify that BlockSizeForFileType can't be called with EXTERNAL FileType PVS-Studio analysis pointed out that if it were called with such a file type, that would lead to division by zero in RequiredBlocks. Also, remove the default: case and cover the enum. Clang warns if the switch doesn't cover all enum values. BUG=660198 ========== to ========== Clarify that BlockSizeForFileType can't be called with EXTERNAL FileType PVS-Studio analysis pointed out that if it were called with such a file type, that would lead to division by zero in RequiredBlocks. Also, remove the default: case since the enum is now covered. Clang warns if the switch doesn't cover all enum values. BUG=660198 ==========
On 2016/10/27 23:13:27, Zhongyi Shi wrote: > Could you update your issue description? It seems inconsistent with the code > change to me. Whoops, I misread the description :(
https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... File net/disk_cache/blockfile/addr.h (right): https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... net/disk_cache/blockfile/addr.h:143: NOTREACHED(); nit: I would prefer to have the default case but with a NOTREACHED() check, you could add a comment then saying EXERNAL case shouldn't called in this case.
https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... File net/disk_cache/blockfile/addr.h (right): https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... net/disk_cache/blockfile/addr.h:143: NOTREACHED(); On 2016/10/27 23:29:43, Zhongyi Shi wrote: > nit: I would prefer to have the default case but with a NOTREACHED() check, you > could add a comment then saying EXERNAL case shouldn't called in this case. But then you won't get any compiler warning if another enum value is added and not handled in the switch.
https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... File net/disk_cache/blockfile/addr.h (right): https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... net/disk_cache/blockfile/addr.h:143: NOTREACHED(); On 2016/10/27 23:33:35, hans wrote: > On 2016/10/27 23:29:43, Zhongyi Shi wrote: > > nit: I would prefer to have the default case but with a NOTREACHED() check, > you > > could add a comment then saying EXERNAL case shouldn't called in this case. > > But then you won't get any compiler warning if another enum value is added and > not handled in the switch. What I am proposing is case BLOCK_EVICTED: return 48; default: // EXTERNAL shouldn't be allowed to call this method. NOTREACHED(); return 0; Are you trying to enforce every enum type to be handled in this method even if it's never called? If it is going to be called while the enum is not handled, the NOTREACH() will fire in the default case. Redundantly, though I will be supportive of, you could also have both CASE EXTERNAL and default to have a NOTREACHED() check.
https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... File net/disk_cache/blockfile/addr.h (right): https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... net/disk_cache/blockfile/addr.h:143: NOTREACHED(); On 2016/10/28 00:01:49, Zhongyi Shi wrote: > On 2016/10/27 23:33:35, hans wrote: > > On 2016/10/27 23:29:43, Zhongyi Shi wrote: > > > nit: I would prefer to have the default case but with a NOTREACHED() check, > > you > > > could add a comment then saying EXERNAL case shouldn't called in this case. > > > > But then you won't get any compiler warning if another enum value is added and > > not handled in the switch. > > What I am proposing is > > case BLOCK_EVICTED: > return 48; > default: > // EXTERNAL shouldn't be allowed to call this method. > NOTREACHED(); > return 0; > > Are you trying to enforce every enum type to be handled in this method even if > it's never called? If it is going to be called while the enum is not handled, > the NOTREACH() will fire in the default case. Redundantly, though I will be > supportive of, you could also have both CASE EXTERNAL and default to have a > NOTREACHED() check. Yes, every enum needs to be handled in the switch, otherwise Clang will warn: ../../net/disk_cache/blockfile/addr.h:127:13: error: enumeration value 'FOO' not handled in switch [-Werror,-Wswitch] switch (file_type) { ^ The easiest way to defeat the warning is of course to have a default case. But not having a default case has the benefit that if a new enumeration value is ever added, we will get a warning if it's not handled in this switch. If we have a default case instead, we'd never know until possibly at runtime. While your suggestion works: default: // EXTERNAL shouldn't be allowed to call this method. NOTREACHED(); return 0; I think it's slightly less clear. How does the reader know that EXTERNAL is the only type that will end up in the default: case?
lgtm https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... File net/disk_cache/blockfile/addr.h (right): https://codereview.chromium.org/2458773003/diff/1/net/disk_cache/blockfile/ad... net/disk_cache/blockfile/addr.h:143: NOTREACHED(); On 2016/10/28 00:57:35, hans wrote: > On 2016/10/28 00:01:49, Zhongyi Shi wrote: > > On 2016/10/27 23:33:35, hans wrote: > > > On 2016/10/27 23:29:43, Zhongyi Shi wrote: > > > > nit: I would prefer to have the default case but with a NOTREACHED() > check, > > > you > > > > could add a comment then saying EXERNAL case shouldn't called in this > case. > > > > > > But then you won't get any compiler warning if another enum value is added > and > > > not handled in the switch. > > > > What I am proposing is > > > > case BLOCK_EVICTED: > > return 48; > > default: > > // EXTERNAL shouldn't be allowed to call this method. > > NOTREACHED(); > > return 0; > > > > Are you trying to enforce every enum type to be handled in this method even if > > it's never called? If it is going to be called while the enum is not handled, > > the NOTREACH() will fire in the default case. Redundantly, though I will be > > supportive of, you could also have both CASE EXTERNAL and default to have a > > NOTREACHED() check. > > Yes, every enum needs to be handled in the switch, otherwise Clang will warn: > > ../../net/disk_cache/blockfile/addr.h:127:13: error: enumeration value 'FOO' not > handled in switch [-Werror,-Wswitch] > switch (file_type) { > ^ > > The easiest way to defeat the warning is of course to have a default case. > > But not having a default case has the benefit that if a new enumeration value is > ever added, we will get a warning if it's not handled in this switch. If we have > a default case instead, we'd never know until possibly at runtime. > > > While your suggestion works: > > default: > // EXTERNAL shouldn't be allowed to call this method. > NOTREACHED(); > return 0; > > I think it's slightly less clear. How does the reader know that EXTERNAL is the > only type that will end up in the default: case? Alright, your argument sold, I agreed that this could enforce handling of new switch type.
The CQ bit was checked by hans@chromium.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Try jobs failed on following builders: android_cronet on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_cron...)
The CQ bit was checked by hans@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from zhongyi@chromium.org Link to the patchset: https://codereview.chromium.org/2458773003/#ps20001 (title: "pacify gcc")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Message was sent while issue was closed.
Description was changed from ========== Clarify that BlockSizeForFileType can't be called with EXTERNAL FileType PVS-Studio analysis pointed out that if it were called with such a file type, that would lead to division by zero in RequiredBlocks. Also, remove the default: case since the enum is now covered. Clang warns if the switch doesn't cover all enum values. BUG=660198 ========== to ========== Clarify that BlockSizeForFileType can't be called with EXTERNAL FileType PVS-Studio analysis pointed out that if it were called with such a file type, that would lead to division by zero in RequiredBlocks. Also, remove the default: case since the enum is now covered. Clang warns if the switch doesn't cover all enum values. BUG=660198 ==========
Message was sent while issue was closed.
Committed patchset #2 (id:20001)
Message was sent while issue was closed.
Description was changed from ========== Clarify that BlockSizeForFileType can't be called with EXTERNAL FileType PVS-Studio analysis pointed out that if it were called with such a file type, that would lead to division by zero in RequiredBlocks. Also, remove the default: case since the enum is now covered. Clang warns if the switch doesn't cover all enum values. BUG=660198 ========== to ========== Clarify that BlockSizeForFileType can't be called with EXTERNAL FileType PVS-Studio analysis pointed out that if it were called with such a file type, that would lead to division by zero in RequiredBlocks. Also, remove the default: case since the enum is now covered. Clang warns if the switch doesn't cover all enum values. BUG=660198 Committed: https://crrev.com/d8c29e03c348bdb7ce8522f22515523de1c20df9 Cr-Commit-Position: refs/heads/master@{#428279} ==========
Message was sent while issue was closed.
Patchset 2 (id:??) landed as https://crrev.com/d8c29e03c348bdb7ce8522f22515523de1c20df9 Cr-Commit-Position: refs/heads/master@{#428279} |
