Skip to content

Commit eabd10d

Browse files
committed
Fix CID 1158180 (Argument cannot be negative) and clean code a bit
Signed-off-by: Stefan Weil <[email protected]>
1 parent 4cc103c commit eabd10d

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/opencl/openclwrapper.cpp

+5-15
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#include <cstdio>
2828
#endif
2929

30-
#define CALLOC LEPT_CALLOC
31-
#define FREE LEPT_FREE
32-
3330
#ifdef USE_OPENCL
3431

3532
#include "opencl_device_selection.h"
@@ -286,8 +283,6 @@ static const char *findString(const char *contentStart, const char *contentEnd,
286283

287284
static ds_status readProFile(const char *fileName, char **content,
288285
size_t *contentSize) {
289-
size_t size = 0;
290-
291286
*contentSize = 0;
292287
*content = nullptr;
293288

@@ -297,13 +292,9 @@ static ds_status readProFile(const char *fileName, char **content,
297292
}
298293

299294
fseek(input, 0L, SEEK_END);
300-
size = ftell(input);
295+
size_t size = ftell(input);
301296
rewind(input);
302-
char *binary = (char *)malloc(size);
303-
if (binary == nullptr) {
304-
fclose(input);
305-
return DS_FILE_ERROR;
306-
}
297+
char *binary = new char[size];
307298
fread(binary, sizeof(char), size, input);
308299
fclose(input);
309300

@@ -320,8 +311,7 @@ static ds_status readProfileFromFile(ds_profile *profile,
320311
ds_score_deserializer deserializer,
321312
const char *file) {
322313
ds_status status = DS_SUCCESS;
323-
char *contentStart = nullptr;
324-
const char *contentEnd = nullptr;
314+
char *contentStart;
325315
size_t contentSize;
326316

327317
if (profile == nullptr) return DS_INVALID_PROFILE;
@@ -332,7 +322,7 @@ static ds_status readProfileFromFile(ds_profile *profile,
332322
const char *dataStart;
333323
const char *dataEnd;
334324

335-
contentEnd = contentStart + contentSize;
325+
const char *contentEnd = contentStart + contentSize;
336326
currentPosition = contentStart;
337327

338328
// parse the version string
@@ -485,7 +475,7 @@ static ds_status readProfileFromFile(ds_profile *profile,
485475
}
486476
}
487477
cleanup:
488-
free(contentStart);
478+
delete[] contentStart;
489479
return status;
490480
}
491481

0 commit comments

Comments
 (0)