MCPcopy Create free account
hub / github.com/Samsung/UTopia / copyMutationPrimitiveType

Method copyMutationPrimitiveType

lib/generation/ProtobufMutator.cpp:160–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160std::string ProtobufMutator::copyMutationPrimitiveType(const Type &MutationType,
161 const FuzzInput &Input) {
162 assert(MutationType.isPrimitiveType() && "Unexpected Program State");
163 std::string Code;
164 auto InputDef = Input.getDef();
165 auto LocalVarName = Input.getProtoVarName();
166 auto MutationVal = getProtoVarVal(LocalVarName);
167 if (InputDef.ArrayLen) {
168 const auto *RelatedArrayDef = Input.ArrayDef;
169 assert(RelatedArrayDef && "Incomplete Arr-ArrLen relationship");
170 const auto &RelatedArrType = RelatedArrayDef->DataType;
171 assert(RelatedArrType && "Incomplete Arr-ArrLen relationship");
172 // NOTE: below condition statements requires order preserving. char [10]
173 // type is both a fixed length array ptr and string ptr, however at here
174 // it should be handled as a fixed length array ptr.
175 if (RelatedArrType->isFixedLengthArrayPtr()) {
176 auto ArrLength =
177 std::to_string(RelatedArrType.get()->getArrayInfo()->getMaxLength());
178 // Mutation array can be larger than fuzz var array
179 Code += SrcGenerator::genAssignStmtWithMaxCheck(
180 LocalVarName,
181 getProtoVarValSize(util::getProtoVarName(RelatedArrayDef->ID)),
182 ArrLength);
183 }
184 else if (RelatedArrType->isStringType()) {
185 Code += SrcGenerator::genAssignStmt(
186 LocalVarName,
187 getProtoVarValSize(util::getProtoVarName(RelatedArrayDef->ID)));
188 }
189 else
190 assert(false && "Incomplete Arr-ArrLen relationship");
191 } else if (InputDef.BufferAllocSize) {
192 // Buffer size must be over 0
193 Code += "if (" + MutationVal + " < 1) return;";
194 Code +=
195 SrcGenerator::genAssignStmt(LocalVarName, MutationVal + " & 0x3fff");
196 } else if (InputDef.LoopExit) {
197 Code += "if (" + MutationVal + " < 0) return;";
198 Code +=
199 SrcGenerator::genAssignStmt(LocalVarName, MutationVal + " & 0x3fff");
200 } else {
201 Code += SrcGenerator::genAssignStmt(LocalVarName, MutationVal);
202 }
203 return Code;
204}
205
206std::string
207ProtobufMutator::saveMutationToFile(const std::string &MutationVarName) {

Callers

nothing calls this directly

Calls 9

getProtoVarNameFunction · 0.85
isPrimitiveTypeMethod · 0.80
getDefMethod · 0.80
getProtoVarNameMethod · 0.80
isFixedLengthArrayPtrMethod · 0.80
getMaxLengthMethod · 0.80
getArrayInfoMethod · 0.80
isStringTypeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected