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

Side by Side Diff: third_party/WebKit/Source/platform/LayoutUnit.h

Issue 2160983007: Avoid integer overflow in LayoutUnit's unary minus operator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Full UnaryMinus test case Created 4 years, 5 months 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 | « no previous file | third_party/WebKit/Source/platform/LayoutUnitTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, Google Inc. All rights reserved. 2 * Copyright (c) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 return LayoutUnit(a) - b; 637 return LayoutUnit(a) - b;
638 } 638 }
639 639
640 inline float operator-(const float a, const LayoutUnit& b) 640 inline float operator-(const float a, const LayoutUnit& b)
641 { 641 {
642 return a - b.toFloat(); 642 return a - b.toFloat();
643 } 643 }
644 644
645 inline LayoutUnit operator-(const LayoutUnit& a) 645 inline LayoutUnit operator-(const LayoutUnit& a)
646 { 646 {
647 // -min() is saturated to max().
648 if (a == LayoutUnit::min())
649 return LayoutUnit::max();
650
647 LayoutUnit returnVal; 651 LayoutUnit returnVal;
648 returnVal.setRawValue(-a.rawValue()); 652 returnVal.setRawValue(-a.rawValue());
649 return returnVal; 653 return returnVal;
650 } 654 }
651 655
652 // For returning the remainder after a division with integer results. 656 // For returning the remainder after a division with integer results.
653 inline LayoutUnit intMod(const LayoutUnit& a, const LayoutUnit& b) 657 inline LayoutUnit intMod(const LayoutUnit& a, const LayoutUnit& b)
654 { 658 {
655 // This calculates the modulo so that: a = static_cast<int>(a / b) * b + int Mod(a, b). 659 // This calculates the modulo so that: a = static_cast<int>(a / b) * b + int Mod(a, b).
656 LayoutUnit returnVal; 660 LayoutUnit returnVal;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 } 811 }
808 812
809 inline std::ostream& operator<<(std::ostream& stream, const LayoutUnit& value) 813 inline std::ostream& operator<<(std::ostream& stream, const LayoutUnit& value)
810 { 814 {
811 return stream << value.toDouble(); 815 return stream << value.toDouble();
812 } 816 }
813 817
814 } // namespace blink 818 } // namespace blink
815 819
816 #endif // LayoutUnit_h 820 #endif // LayoutUnit_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/LayoutUnitTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698