Chromium Code Reviews| Index: courgette/assembly_program.cc |
| =================================================================== |
| --- courgette/assembly_program.cc (revision 80344) |
| +++ courgette/assembly_program.cc (working copy) |
| @@ -110,24 +110,24 @@ |
| DeleteContainedLabels(abs32_labels_); |
| } |
| -void AssemblyProgram::EmitMakeRelocsInstruction() { |
| - Emit(new MakeRelocsInstruction()); |
| +CheckBool AssemblyProgram::EmitMakeRelocsInstruction() { |
| + return Emit(new(std::nothrow) MakeRelocsInstruction()); |
| } |
| -void AssemblyProgram::EmitOriginInstruction(RVA rva) { |
| - Emit(new OriginInstruction(rva)); |
| +CheckBool AssemblyProgram::EmitOriginInstruction(RVA rva) { |
| + return Emit(new(std::nothrow) OriginInstruction(rva)); |
| } |
| -void AssemblyProgram::EmitByteInstruction(uint8 byte) { |
| - Emit(GetByteInstruction(byte)); |
| +CheckBool AssemblyProgram::EmitByteInstruction(uint8 byte) { |
| + return Emit(GetByteInstruction(byte)); |
| } |
| -void AssemblyProgram::EmitRel32(Label* label) { |
| - Emit(new InstructionWithLabel(REL32, label)); |
| +CheckBool AssemblyProgram::EmitRel32(Label* label) { |
| + return Emit(new(std::nothrow) InstructionWithLabel(REL32, label)); |
| } |
| -void AssemblyProgram::EmitAbs32(Label* label) { |
| - Emit(new InstructionWithLabel(ABS32, label)); |
| +CheckBool AssemblyProgram::EmitAbs32(Label* label) { |
| + return Emit(new(std::nothrow) InstructionWithLabel(ABS32, label)); |
| } |
| Label* AssemblyProgram::FindOrMakeAbs32Label(RVA rva) { |
| @@ -170,7 +170,7 @@ |
| Label* AssemblyProgram::FindLabel(RVA rva, RVAToLabel* labels) { |
| Label*& slot = (*labels)[rva]; |
| if (slot == 0) { |
|
grt (UTC plus 2)
2011/04/05 17:10:08
use NULL rather than 0
tommi (sloooow) - chröme
2011/04/05 19:06:53
Done.
|
| - slot = new Label(rva); |
| + slot = new(std::nothrow) Label(rva); |
| } |
| return slot; |
| } |
| @@ -307,7 +307,10 @@ |
| } |
| EncodedProgram* AssemblyProgram::Encode() const { |
| - scoped_ptr<EncodedProgram> encoded(new EncodedProgram()); |
| + scoped_ptr<EncodedProgram> encoded(new(std::nothrow) EncodedProgram()); |
| + if (!encoded.get()) |
| + return NULL; |
| + |
| encoded->set_image_base(image_base_); |
| if (!DefineLabels(abs32_labels_, encoded.get(), |
| @@ -363,9 +366,19 @@ |
| Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) { |
| if (!byte_instruction_cache_) { |
| - byte_instruction_cache_ = new Instruction*[256]; |
| + byte_instruction_cache_ = new(std::nothrow) Instruction*[256]; |
| + if (!byte_instruction_cache_) |
| + return NULL; |
| + |
| for (int i = 0; i < 256; ++i) { |
| - byte_instruction_cache_[i] = new ByteInstruction(static_cast<uint8>(i)); |
| + byte_instruction_cache_[i] = |
| + new(std::nothrow) ByteInstruction(static_cast<uint8>(i)); |
| + if (!byte_instruction_cache_[i]) { |
| + for (int j = 0; j < i; ++j) |
| + delete byte_instruction_cache_[j]; |
| + delete [] byte_instruction_cache_; |
| + return NULL; |
| + } |
| } |
| } |