Skip to content

Commit

Permalink
helpers: Report internal error for failing buffer allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jul 4, 2019
1 parent ae3a4ad commit 7184dd4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions include/evmc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,25 @@ static inline struct evmc_result evmc_make_result(enum evmc_status_code status_c
{
struct evmc_result result;
memset(&result, 0, sizeof(result));
result.status_code = status_code;
result.gas_left = gas_left;
result.output_size = output_size;

if (output_size != 0)
{
uint8_t* buffer = (uint8_t*)malloc(output_size);

if (!buffer)
{
result.status_code = EVMC_OUT_OF_MEMORY;
return result;
}

memcpy(buffer, output_data, output_size);
result.output_data = buffer;
result.output_size = output_size;
result.release = evmc_free_result_memory;
}

result.status_code = status_code;
result.gas_left = gas_left;
return result;
}

Expand Down

0 comments on commit 7184dd4

Please sign in to comment.