Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Issue 2671613003: Add checked_cast to size_t conversion in multibuffer_data_source.cc (Closed)

Created:
3 years, 10 months ago by jrummell
Modified:
3 years, 10 months ago
Reviewers:
hubbe, brucedawson
CC:
chromium-reviews, feature-media-reviews_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add checked_cast to size_t conversion in multibuffer_data_source.cc /analyze on Windows complains about the size_t conversion, so add a checked_cast call to do the conversion. Memory usage is limited to 4Gb, so this should never fail. BUG=687394, 427616 TEST=compiles Review-Url: https://codereview.chromium.org/2671613003 Cr-Commit-Position: refs/heads/master@{#447855} Committed: https://chromium.googlesource.com/chromium/src/+/c88b8d3330e3b647b4e2b266bd9ffc53083e01e7

Patch Set 1 #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+2 lines, -1 line) Patch
M media/blink/multibuffer_data_source.cc View 2 chunks +2 lines, -1 line 2 comments Download

Messages

Total messages: 14 (7 generated)
jrummell
Trivial change. PTAL.
3 years, 10 months ago (2017-02-02 01:17:48 UTC) #3
hubbe
lgtm
3 years, 10 months ago (2017-02-02 04:54:21 UTC) #4
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2671613003/1
3 years, 10 months ago (2017-02-02 20:05:02 UTC) #6
commit-bot: I haz the power
Committed patchset #1 (id:1) as https://chromium.googlesource.com/chromium/src/+/c88b8d3330e3b647b4e2b266bd9ffc53083e01e7
3 years, 10 months ago (2017-02-02 22:16:36 UTC) #9
brucedawson
lgtm to me with the side note that a non-checked cast should also be fine, ...
3 years, 10 months ago (2017-02-02 22:22:52 UTC) #12
brucedawson
Aside: the comment talks about size_t but the code actually uses int64_t.
3 years, 10 months ago (2017-02-02 22:23:23 UTC) #13
jrummell
3 years, 10 months ago (2017-02-03 01:35:40 UTC) #14
Message was sent while issue was closed.
Comments only.

> lgtm to me with the side note that a non-checked cast should also be fine, and
> that you should never have "stop /analyze from complaining" as your main
reason
> to make a change. Only do it if it also makes sense (which I think this does).

Agreed. It does have the potential to generate the wrong result, but currently
won't. However, just in case somebody down the road decides that much bigger
caches are the thing to do, this will avoid the problem.

> Aside: the comment talks about size_t but the code actually uses int64_t.

I was trying to note that the implicit cast from size_t to int64_t done on the
result now uses checked_cast on the intermediate result. Not sure what to say
differently. "Add checked_cast to avoid possibly wrong implicit size_t cast to
int64_t."?

https://codereview.chromium.org/2671613003/diff/1/media/blink/multibuffer_dat...
File media/blink/multibuffer_data_source.cc (right):

https://codereview.chromium.org/2671613003/diff/1/media/blink/multibuffer_dat...
media/blink/multibuffer_data_source.cc:339: return
base::checked_cast<int64_t>(url_data_->CachedSize())
On 2017/02/02 22:22:52, brucedawson (slow) wrote:
> Why do we need a checked cast for converting to a larger size? The cast makes
> sense, I'm only curious about why a checked_cast was felt to be necessary.
> 
> But, checked_cast is probably smart enough to be free in this case so it
doesn't
> really matter.

My understanding is that on some systems size_t is 64 bits, so a simple
conversion is bad. I thought Chromium encouraged use of the helpers, as past
CL's have had comments that I should use them.

Powered by Google App Engine
This is Rietveld 408576698