Skip to content

Commit

Permalink
Addressed coverity issues and some reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hoene committed Jan 24, 2021
1 parent 99ee33d commit 4c1806c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8.12)
project(libmysofa C CXX)

include(CheckCCompilerFlag)
Expand Down
2 changes: 1 addition & 1 deletion src/hdf/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ int treeRead(struct READER *reader, struct DATAOBJECT *data) {

mylog("elements %d size %d\n", elements, size);

if (elements <=0 || size <=0 || elements >= 0x100000 || size > 0x10)
if (elements <= 0 || size <= 0 || elements >= 0x100000 || size > 0x10)
return MYSOFA_INVALID_FORMAT; // LCOV_EXCL_LINE
if (!(output = malloc(elements * size))) {
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
Expand Down
7 changes: 7 additions & 0 deletions src/hdf/dataobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ static int readOHDRHeaderMessageDataspace1(struct READER *reader,
ds->dimension_size[i] =
readValue(reader, reader->superblock.size_of_lengths);
mylog(" dimension %d %" PRIu64 "\n", i, ds->dimension_size[i]);
if (ds->dimension_size[i] > 1000000) {
mylog("dimension_size is too large\n"); // LCOV_EXCL_LINE
return MYSOFA_INVALID_FORMAT; // LCOV_EXCL_LINE
}
} else
readValue(reader, reader->superblock.size_of_lengths);
}
Expand Down Expand Up @@ -836,6 +840,9 @@ int readDataDim(struct READER *reader, struct DATAOBJECT *da,
struct DATATYPE *dt, struct DATASPACE *ds, int dim) {
int i, err;

if (dim >= sizeof(ds->dimension_size) / sizeof(ds->dimension_size[0]))
return MYSOFA_UNSUPPORTED_FORMAT; // LCOV_EXCL_LINE

for (i = 0; i < ds->dimension_size[dim]; i++) {
if (dim + 1 < ds->dimensionality) {
if (!!(err = readDataDim(reader, da, dt, ds, dim + 1))) {
Expand Down
2 changes: 1 addition & 1 deletion src/hdf/fractalhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,

/* TODO: Get definition of this field */
unknown3 = readValue(reader, 2);
if(unknown3 != 0x0000)
if (unknown3 != 0x0000)
return MYSOFA_INVALID_FORMAT;

len = fgetc(reader->fhd);
Expand Down
4 changes: 4 additions & 0 deletions src/hdf/gcol.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ static int readGCOL(struct READER *reader) {
address = ftell(reader->fhd);
end = address;
collection_size = readValue(reader, reader->superblock.size_of_lengths);
if (collection_size > 0x400000000) {
mylog("collection_size is too large\n");
return MYSOFA_INVALID_FORMAT;
}
end += collection_size - 8;

while (ftell(reader->fhd) <= end - 8 - reader->superblock.size_of_lengths) {
Expand Down
3 changes: 2 additions & 1 deletion src/hrtf/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf) {
==============================================================================
*/

if (hrtf->C != 3 || hrtf->I != 1 || hrtf->E != 1 || hrtf->R != 2 || hrtf->M == 0)
if (hrtf->C != 3 || hrtf->I != 1 || hrtf->E != 1 || hrtf->R != 2 ||
hrtf->M == 0)
return MYSOFA_INVALID_DIMENSIONS; // LCOV_EXCL_LINE

/* verify format */
Expand Down
3 changes: 2 additions & 1 deletion src/hrtf/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ char *mysofa_strdup(const char *str) {

int verifyAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name, char *value) {
while (attr) {
if (attr->name && !strcmp(name, attr->name) && attr->value && !strcmp(value, attr->value))
if (attr->name && !strcmp(name, attr->name) && attr->value &&
!strcmp(value, attr->value))
return 1;
attr = attr->next;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void test_easy_open() {
int err = 0;
int filterlength;

easy = mysofa_open("tests/MIT_KEMAR_normal_pinna.old.sofa", 8000., &filterlength,
&err);
easy = mysofa_open("tests/MIT_KEMAR_normal_pinna.old.sofa", 8000.,
&filterlength, &err);
if (!easy) {
CU_FAIL_FATAL("Error reading file.");
return;
Expand Down

0 comments on commit 4c1806c

Please sign in to comment.