Skip to content

Commit 5fe7fbf

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Don't crash when copying a null Rect Bug #7158068" into jb-mr1-dev
2 parents 0c348b6 + dd4b1fe commit 5fe7fbf

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

graphics/java/android/graphics/Rect.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ public Rect(int left, int top, int right, int bottom) {
6969
* rectangle.
7070
*/
7171
public Rect(Rect r) {
72-
left = r.left;
73-
top = r.top;
74-
right = r.right;
75-
bottom = r.bottom;
72+
if (r == null) {
73+
left = top = right = bottom = 0;
74+
} else {
75+
left = r.left;
76+
top = r.top;
77+
right = r.right;
78+
bottom = r.bottom;
79+
}
7680
}
7781

7882
@Override

graphics/java/android/graphics/RectF.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,25 @@ public RectF(float left, float top, float right, float bottom) {
6666
* rectangle.
6767
*/
6868
public RectF(RectF r) {
69-
left = r.left;
70-
top = r.top;
71-
right = r.right;
72-
bottom = r.bottom;
69+
if (r == null) {
70+
left = top = right = bottom = 0.0f;
71+
} else {
72+
left = r.left;
73+
top = r.top;
74+
right = r.right;
75+
bottom = r.bottom;
76+
}
7377
}
7478

7579
public RectF(Rect r) {
76-
left = r.left;
77-
top = r.top;
78-
right = r.right;
79-
bottom = r.bottom;
80+
if (r == null) {
81+
left = top = right = bottom = 0.0f;
82+
} else {
83+
left = r.left;
84+
top = r.top;
85+
right = r.right;
86+
bottom = r.bottom;
87+
}
8088
}
8189

8290
@Override

0 commit comments

Comments
 (0)