OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Fuzz.h" | 8 #include "Fuzz.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 #include "SkParsePath.h" | 10 #include "SkParsePath.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 { 'V', 1 }, | 22 { 'V', 1 }, |
23 { 'L', 2 }, | 23 { 'L', 2 }, |
24 { 'Q', 4 }, | 24 { 'Q', 4 }, |
25 { 'T', 2 }, | 25 { 'T', 2 }, |
26 { 'C', 6 }, | 26 { 'C', 6 }, |
27 { 'S', 4 }, | 27 { 'S', 4 }, |
28 { 'A', 4 }, | 28 { 'A', 4 }, |
29 { 'Z', 0 }, | 29 { 'Z', 0 }, |
30 }; | 30 }; |
31 | 31 |
32 bool gEasy = false; // set to true while debugging to suppress unusual whitespa ce | 32 bool _gEasy = false; // set to true while debugging to suppress unusual whitesp ace |
mtklein_C
2016/10/03 17:39:39
The author of this fuzz probably meant to write
kjlubick
2016/10/03 18:05:45
Thanks for the tip. Done.
| |
33 | 33 |
34 // mostly do nothing, then bias towards spaces | 34 // mostly do nothing, then bias towards spaces |
35 const char gWhiteSpace[] = { 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0x09, 0 x0D, 0x0A }; | 35 const char gWhiteSpace[] = { 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0x09, 0 x0D, 0x0A }; |
36 | 36 |
37 static void add_white(Fuzz* fuzz, SkString* atom) { | 37 static void add_white(Fuzz* fuzz, SkString* atom) { |
38 if (gEasy) { | 38 if (_gEasy) { |
39 atom->append(" "); | 39 atom->append(" "); |
40 return; | 40 return; |
41 } | 41 } |
42 int reps = fuzz->nextRangeU(0, 2); | 42 int reps = fuzz->nextRangeU(0, 2); |
43 for (int rep = 0; rep < reps; ++rep) { | 43 for (int rep = 0; rep < reps; ++rep) { |
44 int index = fuzz->nextRangeU(0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1); | 44 int index = fuzz->nextRangeU(0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1); |
45 if (gWhiteSpace[index]) { | 45 if (gWhiteSpace[index]) { |
46 atom->append(&gWhiteSpace[index], 1); | 46 atom->append(&gWhiteSpace[index], 1); |
47 } | 47 } |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 static void add_comma(Fuzz* fuzz, SkString* atom) { | 51 static void add_comma(Fuzz* fuzz, SkString* atom) { |
52 if (gEasy) { | 52 if (_gEasy) { |
53 atom->append(","); | 53 atom->append(","); |
54 return; | 54 return; |
55 } | 55 } |
56 size_t count = atom->size(); | 56 size_t count = atom->size(); |
57 add_white(fuzz, atom); | 57 add_white(fuzz, atom); |
58 if (fuzz->nextBool()) { | 58 if (fuzz->nextBool()) { |
59 atom->append(","); | 59 atom->append(","); |
60 } | 60 } |
61 do { | 61 do { |
62 add_white(fuzz, atom); | 62 add_white(fuzz, atom); |
63 } while (count == atom->size()); | 63 } while (count == atom->size()); |
64 } | 64 } |
65 | 65 |
66 static void add_some_white(Fuzz* fuzz, SkString* atom) { | 66 static void add_some_white(Fuzz* fuzz, SkString* atom) { |
67 size_t count = atom->size(); | 67 size_t count = atom->size(); |
68 do { | 68 do { |
69 add_white(fuzz, atom); | 69 add_white(fuzz, atom); |
70 } while (count == atom->size()); | 70 } while (count == atom->size()); |
71 } | 71 } |
72 | 72 |
73 SkString MakeRandomParsePathPiece(Fuzz* fuzz) { | 73 SkString MakeRandomParsePathPiece(Fuzz* fuzz) { |
74 SkString atom; | 74 SkString atom; |
75 int index = fuzz->nextRangeU(0, (int) SK_ARRAY_COUNT(gLegal) - 1); | 75 int index = fuzz->nextRangeU(0, (int) SK_ARRAY_COUNT(gLegal) - 1); |
76 const Legal& legal = gLegal[index]; | 76 const Legal& legal = gLegal[index]; |
77 gEasy ? atom.append("\n") : add_white(fuzz, &atom); | 77 _gEasy ? atom.append("\n") : add_white(fuzz, &atom); |
78 char symbol = legal.fSymbol | (fuzz->nextBool() ? 0x20 : 0); | 78 char symbol = legal.fSymbol | (fuzz->nextBool() ? 0x20 : 0); |
79 atom.append(&symbol, 1); | 79 atom.append(&symbol, 1); |
80 int reps = fuzz->nextRangeU(1, 3); | 80 int reps = fuzz->nextRangeU(1, 3); |
81 for (int rep = 0; rep < reps; ++rep) { | 81 for (int rep = 0; rep < reps; ++rep) { |
82 for (int index = 0; index < legal.fScalars; ++index) { | 82 for (int index = 0; index < legal.fScalars; ++index) { |
83 SkScalar coord = fuzz->nextRangeF(0, 100); | 83 SkScalar coord = fuzz->nextRangeF(0, 100); |
84 add_white(fuzz, &atom); | 84 add_white(fuzz, &atom); |
85 atom.appendScalar(coord); | 85 atom.appendScalar(coord); |
86 if (rep < reps - 1 && index < legal.fScalars - 1) { | 86 if (rep < reps - 1 && index < legal.fScalars - 1) { |
87 add_comma(fuzz, &atom); | 87 add_comma(fuzz, &atom); |
(...skipping 18 matching lines...) Expand all Loading... | |
106 SkString spec; | 106 SkString spec; |
107 uint32_t count = fuzz->nextRangeU(0, 40); | 107 uint32_t count = fuzz->nextRangeU(0, 40); |
108 for (uint32_t i = 0; i < count; ++i) { | 108 for (uint32_t i = 0; i < count; ++i) { |
109 spec.append(MakeRandomParsePathPiece(fuzz)); | 109 spec.append(MakeRandomParsePathPiece(fuzz)); |
110 } | 110 } |
111 SkDebugf("SkParsePath::FromSVGString(%s, &path);\n",spec.c_str()); | 111 SkDebugf("SkParsePath::FromSVGString(%s, &path);\n",spec.c_str()); |
112 if (!SkParsePath::FromSVGString(spec.c_str(), &path)){ | 112 if (!SkParsePath::FromSVGString(spec.c_str(), &path)){ |
113 fuzz->signalBug(); | 113 fuzz->signalBug(); |
114 } | 114 } |
115 } | 115 } |
OLD | NEW |