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

Side by Side Diff: media/base/video_util.cc

Issue 2528243002: Fix silent truncations when extracting values from CheckedNumeric (Closed)
Patch Set: compile fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | third_party/crashpad/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_util.h" 5 #include "media/base/video_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 263 }
264 } 264 }
265 265
266 // Helper function to return |a| divided by |b|, rounded to the nearest integer. 266 // Helper function to return |a| divided by |b|, rounded to the nearest integer.
267 static int RoundedDivision(int64_t a, int b) { 267 static int RoundedDivision(int64_t a, int b) {
268 DCHECK_GE(a, 0); 268 DCHECK_GE(a, 0);
269 DCHECK_GT(b, 0); 269 DCHECK_GT(b, 0);
270 base::CheckedNumeric<uint64_t> result(a); 270 base::CheckedNumeric<uint64_t> result(a);
271 result += b / 2; 271 result += b / 2;
272 result /= b; 272 result /= b;
273 return base::checked_cast<int>(result.ValueOrDie()); 273 return base::ValueOrDieForType<int>(result);
274 } 274 }
275 275
276 // Common logic for the letterboxing and scale-within/scale-encompassing 276 // Common logic for the letterboxing and scale-within/scale-encompassing
277 // functions. Scales |size| to either fit within or encompass |target|, 277 // functions. Scales |size| to either fit within or encompass |target|,
278 // depending on whether |fit_within_target| is true. 278 // depending on whether |fit_within_target| is true.
279 static gfx::Size ScaleSizeToTarget(const gfx::Size& size, 279 static gfx::Size ScaleSizeToTarget(const gfx::Size& size,
280 const gfx::Size& target, 280 const gfx::Size& target,
281 bool fit_within_target) { 281 bool fit_within_target) {
282 if (size.IsEmpty()) 282 if (size.IsEmpty())
283 return gfx::Size(); // Corner case: Aspect ratio is undefined. 283 return gfx::Size(); // Corner case: Aspect ratio is undefined.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 dst_frame->stride(VideoFrame::kVPlane), 413 dst_frame->stride(VideoFrame::kVPlane),
414 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, 414 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane,
415 dst_frame->coded_size()), 415 dst_frame->coded_size()),
416 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, 416 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane,
417 src_frame.visible_rect().size())); 417 src_frame.visible_rect().size()));
418 418
419 return true; 419 return true;
420 } 420 }
421 421
422 } // namespace media 422 } // namespace media
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | third_party/crashpad/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698