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

Method copyMutationPointerType

lib/generation/ProtobufMutator.cpp:119–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119std::string ProtobufMutator::copyMutationPointerType(const Type &MutationType,
120 const FuzzInput &Input) {
121 assert(MutationType.isPointerType() && "Unexpected Program State");
122 std::string Code;
123 auto InputDef = Input.getDef();
124 auto LocalVarName = Input.getProtoVarName();
125 // Base type can not be single ptr Array or String
126 auto MutationVal = getProtoVarVal(LocalVarName);
127 auto MutationValBegin = MutationVal + ".begin()";
128 auto MutationSize = getProtoVarValSize(LocalVarName);
129 if (InputDef.FilePath) {
130 Code += saveMutationToFile(LocalVarName);
131 } else if (MutationType.isFixedLengthArrayPtr()) {
132 auto FuzzArrSize = util::getAvasFuzzSizeVarName(Input.getFuzzVarName());
133 auto ArrLength =
134 std::to_string(MutationType.getArrayInfo()->getMaxLength());
135 // Mutation array can be smaller than fuzz var array
136 Code += SrcGenerator::genAssignStmtWithMaxCheck(FuzzArrSize, ArrLength,
137 MutationSize);
138 // Array copy
139 if (MutationType.getPointeeType()->isEnumType()) { // needs type casting
140 Code += "for(int i=0;i<" + FuzzArrSize + ";++i) {" + LocalVarName +
141 "[i]=static_cast<" +
142 MutationType.getPointeeType()->getTypeName() + ">(" +
143 MutationVal + "[i]);}";
144 } else {
145 addHeader("<algorithm>");
146 Code += "std::copy(" + MutationValBegin + ", " + MutationValBegin +
147 " + " + FuzzArrSize + ", " + LocalVarName + ");";
148 }
149 } else if (MutationType.isStringType()) {
150 auto StrVal = SrcGenerator::genStrToCStr(MutationVal);
151 auto OrgTypeName =
152 util::stripConstExpr(MutationType.getPointeeType()->getASTTypeName());
153 if (OrgTypeName.compare("char") != 0)
154 StrVal = "reinterpret_cast<" + OrgTypeName + "*>(" + StrVal + ")";
155 Code += SrcGenerator::genAssignStmt(LocalVarName, StrVal);
156 }
157 return Code;
158}
159
160std::string ProtobufMutator::copyMutationPrimitiveType(const Type &MutationType,
161 const FuzzInput &Input) {

Callers

nothing calls this directly

Calls 15

getAvasFuzzSizeVarNameFunction · 0.85
stripConstExprFunction · 0.85
isPointerTypeMethod · 0.80
getDefMethod · 0.80
getProtoVarNameMethod · 0.80
isFixedLengthArrayPtrMethod · 0.80
getFuzzVarNameMethod · 0.80
getMaxLengthMethod · 0.80
getArrayInfoMethod · 0.80
isEnumTypeMethod · 0.80
getPointeeTypeMethod · 0.80
getTypeNameMethod · 0.80

Tested by

no test coverage detected