| 158 | } |
| 159 | |
| 160 | std::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 | |
| 206 | std::string |
| 207 | ProtobufMutator::saveMutationToFile(const std::string &MutationVarName) { |
nothing calls this directly
no test coverage detected