Skip to content

Commit

Permalink
Cleanup function BKDataLoadRaw
Browse files Browse the repository at this point in the history
  • Loading branch information
detomon committed Sep 11, 2024
1 parent 063a3ee commit b463769
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/BKData.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* IN THE SOFTWARE.
*/

#include "BKBase.h"
#include "BKData_internal.h"
#include "BKTone.h"
#include "BKWaveFileReader.h"
Expand Down Expand Up @@ -592,6 +593,7 @@ BKInt BKDataSetData(BKData* data, void const* frameData, BKUInt dataSize, BKUInt

BKInt BKDataLoadRaw(BKData* data, FILE* file, BKUInt numChannels, BKEnum params) {
BKSize offset = ftell(file);
BKInt ret = BK_SUCCESS;

if (offset < 0) {
return BK_FILE_ERROR;
Expand All @@ -607,19 +609,25 @@ BKInt BKDataLoadRaw(BKData* data, FILE* file, BKUInt numChannels, BKEnum params)
size -= offset;
void* frames = malloc(size);

if (frames == NULL) {
return BK_ALLOCATION_ERROR;
if (!frames) {
ret = BK_ALLOCATION_ERROR;
goto error;
}

fseek(file, offset, SEEK_SET);

if (fread(frames, sizeof(char), size, file) < size) {
return BK_FILE_ERROR;
ret = BK_FILE_ERROR;
goto error;
}

BKInt ret = BKDataSetData(data, frames, (BKUInt)size, numChannels, params);
ret = BKDataSetData(data, frames, (BKUInt)size, numChannels, params);

free(frames);
error: {
if (frames) {
free(frames);
}
}

return ret;
}
Expand Down

0 comments on commit b463769

Please sign in to comment.