Skip to content

Commit

Permalink
Add exclusions for branch coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Brodsky committed Feb 5, 2021
1 parent a825535 commit b4fbc82
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/apps/testapps/testH3ToLocalIj.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ SUITE(h3ToLocalIj) {

TEST(experimentalH3ToLocalIjInvalid) {
CoordIJ ij;
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(bc1, 0x7fffffffffffffff,
&ij) != 0,
"invalid index");
H3Index invalidIndex = 0x7fffffffffffffff;
H3_SET_RESOLUTION(invalidIndex, H3_GET_RESOLUTION(bc1));
t_assert(
H3_EXPORT(experimentalH3ToLocalIj)(bc1, invalidIndex, &ij) != 0,
"invalid index");
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(0x7fffffffffffffff, bc1,
&ij) != 0,
"invalid origin");
Expand Down
2 changes: 2 additions & 0 deletions src/apps/testapps/testH3ToParent.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ SUITE(h3ToParent) {
"Invalid resolution fails");
t_assert(H3_EXPORT(h3ToParent)(child, 15) == 0,
"Invalid resolution fails");
t_assert(H3_EXPORT(h3ToParent)(child, 16) == 0,
"Invalid resolution fails");
}
}
4 changes: 3 additions & 1 deletion src/h3lib/lib/algos.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ H3Index h3NeighborRotations(H3Index origin, Direction dir, int* rotations) {

int newRotations = 0;
int oldBaseCell = H3_GET_BASE_CELL(out);
if (oldBaseCell < 0 || oldBaseCell >= NUM_BASE_CELLS) {
if (oldBaseCell < 0 ||
oldBaseCell >= NUM_BASE_CELLS) { // LCOV_EXCL_BR_LINE
// Base cells less than zero can not be represented in an index
return H3_NULL;
}
Direction oldLeadingDigit = _h3LeadingNonZeroDigit(out);
Expand Down
3 changes: 2 additions & 1 deletion src/h3lib/lib/baseCells.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ const BaseCellData baseCellData[NUM_BASE_CELLS] = {

/** @brief Return whether or not the indicated base cell is a pentagon. */
int _isBaseCellPentagon(int baseCell) {
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) {
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { // LCOV_EXCL_BR_LINE
// Base cells less than zero can not be represented in an index
return false;
}
return baseCellData[baseCell].isPentagon;
Expand Down
22 changes: 16 additions & 6 deletions src/h3lib/lib/h3Index.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ int H3_EXPORT(h3IsValid)(H3Index h) {
if (H3_GET_RESERVED_BITS(h) != 0) return 0;

int baseCell = H3_GET_BASE_CELL(h);
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) return 0;
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { // LCOV_EXCL_BR_LINE
// Base cells less than zero can not be represented in an index
return 0;
}

int res = H3_GET_RESOLUTION(h);
if (res < 0 || res > MAX_H3_RES) return 0;
if (res < 0 || res > MAX_H3_RES) { // LCOV_EXCL_BR_LINE
// Resolutions less than zero can not be represented in an index
return 0;
}

bool foundFirstNonZeroDigit = false;
for (int r = 1; r <= res; r++) {
Expand Down Expand Up @@ -143,12 +149,12 @@ void setH3Index(H3Index* hp, int res, int baseCell, Direction initDigit) {
*/
H3Index H3_EXPORT(h3ToParent)(H3Index h, int parentRes) {
int childRes = H3_GET_RESOLUTION(h);
if (parentRes > childRes) {
if (parentRes < 0 || parentRes > MAX_H3_RES) {
return H3_NULL;
} else if (parentRes > childRes) {
return H3_NULL;
} else if (parentRes == childRes) {
return h;
} else if (parentRes < 0 || parentRes > MAX_H3_RES) {
return H3_NULL;
}
H3Index parentH = H3_SET_RESOLUTION(h, parentRes);
for (int i = parentRes + 1; i <= childRes; i++) {
Expand Down Expand Up @@ -787,8 +793,12 @@ int _h3ToFaceIjkWithInitializedFijk(H3Index h, FaceIJK* fijk) {
*/
void _h3ToFaceIjk(H3Index h, FaceIJK* fijk) {
int baseCell = H3_GET_BASE_CELL(h);
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) {
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { // aaa TODO
// Base cells less than zero can not be represented in an index
// TODO: Indicate an error to the caller
// To prevent reading uninitialized memory, we zero the output.
fijk->face = 0;
fijk->coord.i = fijk->coord.j = fijk->coord.k = 0;
return;
}
// adjust for the pentagonal missing sequence; all of sub-sequence 5 needs
Expand Down
11 changes: 8 additions & 3 deletions src/h3lib/lib/localij.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ int h3ToLocalIjk(H3Index origin, H3Index h3, CoordIJK* out) {
int originBaseCell = H3_GET_BASE_CELL(origin);
int baseCell = H3_GET_BASE_CELL(h3);

if (originBaseCell < 0 || originBaseCell >= NUM_BASE_CELLS) {
if (originBaseCell < 0 || // LCOV_EXCL_BR_LINE
originBaseCell >= NUM_BASE_CELLS) {
// Base cells less than zero can not be represented in an index
return 1;
}
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) {
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { // LCOV_EXCL_BR_LINE
// Base cells less than zero can not be represented in an index
return 1;
}

Expand Down Expand Up @@ -287,7 +290,9 @@ int h3ToLocalIjk(H3Index origin, H3Index h3, CoordIJK* out) {
int localIjkToH3(H3Index origin, const CoordIJK* ijk, H3Index* out) {
int res = H3_GET_RESOLUTION(origin);
int originBaseCell = H3_GET_BASE_CELL(origin);
if (originBaseCell < 0 || originBaseCell >= NUM_BASE_CELLS) {
if (originBaseCell < 0 || // LCOV_EXCL_BR_LINE
originBaseCell >= NUM_BASE_CELLS) {
// Base cells less than zero can not be represented in an index
return 1;
}
int originOnPent = _isBaseCellPentagon(originBaseCell);
Expand Down

0 comments on commit b4fbc82

Please sign in to comment.