Skip to content

Commit

Permalink
Fix CID 1158180 (Argument cannot be negative) and clean code a bit
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Jun 30, 2018
1 parent 4cc103c commit eabd10d
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include <cstdio>
#endif

#define CALLOC LEPT_CALLOC
#define FREE LEPT_FREE

#ifdef USE_OPENCL

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

static ds_status readProFile(const char *fileName, char **content,
size_t *contentSize) {
size_t size = 0;

*contentSize = 0;
*content = nullptr;

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

fseek(input, 0L, SEEK_END);
size = ftell(input);
size_t size = ftell(input);
rewind(input);
char *binary = (char *)malloc(size);
if (binary == nullptr) {
fclose(input);
return DS_FILE_ERROR;
}
char *binary = new char[size];
fread(binary, sizeof(char), size, input);
fclose(input);

Expand All @@ -320,8 +311,7 @@ static ds_status readProfileFromFile(ds_profile *profile,
ds_score_deserializer deserializer,
const char *file) {
ds_status status = DS_SUCCESS;
char *contentStart = nullptr;
const char *contentEnd = nullptr;
char *contentStart;
size_t contentSize;

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

contentEnd = contentStart + contentSize;
const char *contentEnd = contentStart + contentSize;
currentPosition = contentStart;

// parse the version string
Expand Down Expand Up @@ -485,7 +475,7 @@ static ds_status readProfileFromFile(ds_profile *profile,
}
}
cleanup:
free(contentStart);
delete[] contentStart;
return status;
}

Expand Down

0 comments on commit eabd10d

Please sign in to comment.