Skip to content

Commit

Permalink
check nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
octu0 committed Jan 10, 2024
1 parent 210bae6 commit db1c42b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions c-encodec-cpp/cencodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ cencodec_compressed* cencodec_get_compress_codes(void* ectx) {

data->codes_len = ctx->out_codes.size();
data->codes = (int32_t*) malloc(data->codes_len * sizeof(int32_t));
if(nullptr == data->codes) {
free(data);
return nullptr;
}
memcpy(data->codes, ctx->out_codes.data(), data->codes_len * sizeof(int32_t));
return data;
}
Expand Down Expand Up @@ -73,6 +77,10 @@ cencodec_decompressed* cencodec_get_decompress_audio(void* ectx) {

data->audio_len = ctx->out_audio.size();
data->audio = (float*) malloc(data->audio_len * sizeof(float));
if(nullptr == data->audio){
free(data);
return nullptr;
}
memcpy(data->audio, ctx->out_audio.data(), data->audio_len * sizeof(float));
return data;
}
Expand Down

0 comments on commit db1c42b

Please sign in to comment.