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

Side by Side Diff: fuzz/FuzzParsePath.cpp

Issue 2478593003: Avoid params being initialized out of order in Fuzzer (Closed)
Patch Set: Created 4 years, 1 month 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 | « fuzz/FuzzGradients.cpp ('k') | fuzz/FuzzPathop.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 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 21 matching lines...) Expand all
32 static bool gEasy = false; // set to true while debugging to suppress unusual w hitespace 32 static bool gEasy = false; // set to true while debugging to suppress unusual w hitespace
33 33
34 // mostly do nothing, then bias towards spaces 34 // mostly do nothing, then bias towards spaces
35 static const char gWhiteSpace[] = { 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0x09, 0x0D, 0x0A }; 35 static const char gWhiteSpace[] = { 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0x09, 0x0D, 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->nextRange(0, 2); 42 int reps; fuzz->nextRange(&reps, 0, 2);
43 for (int rep = 0; rep < reps; ++rep) { 43 for (int rep = 0; rep < reps; ++rep) {
44 int index = fuzz->nextRange(0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1); 44 int index; fuzz->nextRange(&index, 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_some_white(Fuzz* fuzz, SkString* atom) { 51 static void add_some_white(Fuzz* fuzz, SkString* atom) {
52 for(int i = 0; i < 10; i++) { 52 for(int i = 0; i < 10; i++) {
53 add_white(fuzz, atom); 53 add_white(fuzz, atom);
54 } 54 }
55 } 55 }
56 56
57 static void add_comma(Fuzz* fuzz, SkString* atom) { 57 static void add_comma(Fuzz* fuzz, SkString* atom) {
58 if (gEasy) { 58 if (gEasy) {
59 atom->append(","); 59 atom->append(",");
60 return; 60 return;
61 } 61 }
62 add_white(fuzz, atom); 62 add_white(fuzz, atom);
63 if (fuzz->next<bool>()) { 63 bool b; fuzz->next(&b);
64 if (b) {
64 atom->append(","); 65 atom->append(",");
65 } 66 }
66 add_some_white(fuzz, atom); 67 add_some_white(fuzz, atom);
67 } 68 }
68 69
69 SkString MakeRandomParsePathPiece(Fuzz* fuzz) { 70 SkString MakeRandomParsePathPiece(Fuzz* fuzz) {
70 SkString atom; 71 SkString atom;
71 int index = fuzz->nextRange(0, (int) SK_ARRAY_COUNT(gLegal) - 1); 72 int index; fuzz->nextRange(&index, 0, (int) SK_ARRAY_COUNT(gLegal) - 1);
72 const Legal& legal = gLegal[index]; 73 const Legal& legal = gLegal[index];
73 gEasy ? atom.append("\n") : add_white(fuzz, &atom); 74 gEasy ? atom.append("\n") : add_white(fuzz, &atom);
74 char symbol = legal.fSymbol | (fuzz->next<bool>() ? 0x20 : 0); 75 bool b; fuzz->next(&b);
76 char symbol = legal.fSymbol | (b ? 0x20 : 0);
75 atom.append(&symbol, 1); 77 atom.append(&symbol, 1);
76 int reps = fuzz->nextRange(1, 3); 78 int reps; fuzz->nextRange(&reps, 1, 3);
77 for (int rep = 0; rep < reps; ++rep) { 79 for (int rep = 0; rep < reps; ++rep) {
78 for (int index = 0; index < legal.fScalars; ++index) { 80 for (int index = 0; index < legal.fScalars; ++index) {
79 SkScalar coord = fuzz->nextRange(0.0f, 100.0f); 81 SkScalar coord; fuzz->nextRange(&coord, 0.0f, 100.0f);
80 add_white(fuzz, &atom); 82 add_white(fuzz, &atom);
81 atom.appendScalar(coord); 83 atom.appendScalar(coord);
82 if (rep < reps - 1 && index < legal.fScalars - 1) { 84 if (rep < reps - 1 && index < legal.fScalars - 1) {
83 add_comma(fuzz, &atom); 85 add_comma(fuzz, &atom);
84 } else { 86 } else {
85 add_some_white(fuzz, &atom); 87 add_some_white(fuzz, &atom);
86 } 88 }
87 if ('A' == legal.fSymbol && 1 == index) { 89 if ('A' == legal.fSymbol && 1 == index) {
88 atom.appendScalar(fuzz->nextRange(-720.0f, 720.0f)); 90 SkScalar s; fuzz->nextRange(&s, -720.0f, 720.0f);
91 atom.appendScalar(s);
89 add_comma(fuzz, &atom); 92 add_comma(fuzz, &atom);
90 atom.appendU32(fuzz->nextRange(0, 1)); 93 int i; fuzz->nextRange(&i, 0, 1);
94 atom.appendU32(i);
91 add_comma(fuzz, &atom); 95 add_comma(fuzz, &atom);
92 atom.appendU32(fuzz->nextRange(0, 1)); 96 fuzz->nextRange(&i, 0, 1);
97 atom.appendU32(i);
93 add_comma(fuzz, &atom); 98 add_comma(fuzz, &atom);
94 } 99 }
95 } 100 }
96 } 101 }
97 return atom; 102 return atom;
98 } 103 }
99 104
100 DEF_FUZZ(ParsePath, fuzz) { 105 DEF_FUZZ(ParsePath, fuzz) {
101 SkPath path; 106 SkPath path;
102 SkString spec; 107 SkString spec;
103 uint32_t count = fuzz->nextRange(0, 40); 108 int count; fuzz->nextRange(&count, 0, 40);
104 for (uint32_t i = 0; i < count; ++i) { 109 for (int i = 0; i < count; ++i) {
105 spec.append(MakeRandomParsePathPiece(fuzz)); 110 spec.append(MakeRandomParsePathPiece(fuzz));
106 } 111 }
107 SkDebugf("SkParsePath::FromSVGString(%s, &path);\n",spec.c_str()); 112 SkDebugf("SkParsePath::FromSVGString(%s, &path);\n",spec.c_str());
108 if (!SkParsePath::FromSVGString(spec.c_str(), &path)){ 113 if (!SkParsePath::FromSVGString(spec.c_str(), &path)){
109 SkDebugf("Could not decode path\n"); 114 SkDebugf("Could not decode path\n");
110 } 115 }
111 } 116 }
OLDNEW
« no previous file with comments | « fuzz/FuzzGradients.cpp ('k') | fuzz/FuzzPathop.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698