| 117 | } |
| 118 | |
| 119 | std::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 | |
| 160 | std::string ProtobufMutator::copyMutationPrimitiveType(const Type &MutationType, |
| 161 | const FuzzInput &Input) { |
nothing calls this directly
no test coverage detected