| 74 | } |
| 75 | |
| 76 | std::string ProtobufMutator::genFuzzVarAssign(FuzzInput &FuzzingInput) { |
| 77 | std::string Code; |
| 78 | // Use intermediate LocalVar for handling pointers |
| 79 | auto LocalVarName = FuzzingInput.getProtoVarName(); |
| 80 | auto FuzzVarName = FuzzingInput.getFuzzVarName(); |
| 81 | const auto *MutationType = FuzzingInput.getFTGType().getRealType(); |
| 82 | |
| 83 | assert(MutationType && "Unexpected Program State"); |
| 84 | |
| 85 | // LocalVar declaration |
| 86 | Code += SrcGenerator::genDeclStmt(*MutationType, LocalVarName); |
| 87 | |
| 88 | // Copy mutation result to LocalVar |
| 89 | if (MutationType->isPointerType()) { |
| 90 | Code += copyMutationPointerType(*MutationType, FuzzingInput); |
| 91 | } else if (MutationType->isEnumType()) { |
| 92 | Code += copyMutationEnumType(*MutationType, FuzzingInput); |
| 93 | } else if (MutationType->isPrimitiveType()) { |
| 94 | Code += copyMutationPrimitiveType(*MutationType, FuzzingInput); |
| 95 | } else { |
| 96 | assert(false && "Unsupported mutation type"); |
| 97 | } |
| 98 | |
| 99 | // Copy LocalVar to FuzzVar |
| 100 | auto &FuzzVarType = FuzzingInput.getFTGType(); |
| 101 | if (&FuzzVarType == MutationType) { |
| 102 | Code += SrcGenerator::genAssignStmt(FuzzVarName, LocalVarName); |
| 103 | } else { // FuzzVar is pointer type |
| 104 | auto PtrVarName = LocalVarName; |
| 105 | auto TypeStr = SrcGenerator::genTypeStr(*MutationType); |
| 106 | const auto *TypePtr = &FuzzVarType; |
| 107 | while (MutationType != TypePtr) { |
| 108 | Code += SrcGenerator::genAssignStmt(TypeStr + "* " + PtrVarName + "p", |
| 109 | "&" + PtrVarName); |
| 110 | TypePtr = TypePtr->getPointeeType(); |
| 111 | PtrVarName += "p"; |
| 112 | TypeStr += "*"; |
| 113 | } |
| 114 | Code += SrcGenerator::genAssignStmt(FuzzVarName, PtrVarName); |
| 115 | } |
| 116 | return Code; |
| 117 | } |
| 118 | |
| 119 | std::string ProtobufMutator::copyMutationPointerType(const Type &MutationType, |
| 120 | const FuzzInput &Input) { |
nothing calls this directly
no test coverage detected