+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ endif()

set(H3_COMPILE_FLAGS "")
set(H3_LINK_FLAGS "")
option(ENABLE_WARNINGS "Enables compiler warnings" ON)
if(ENABLE_WARNINGS)
if(WIN32)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, /W2 is a MSVC flag and you should check MSVC instead. MSVC isn't the only Windows compiler available.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting! Would you mind filing an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry! I've opened an issue for this: #980

I'll open a PR too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list(APPEND H3_COMPILE_FLAGS /W2)
else()
list(APPEND H3_COMPILE_FLAGS -Wall)
endif()
endif()

if(NOT WIN32)
# Compiler options are set only on non-Windows, since these options
# are not correct for MSVC.
list(APPEND H3_COMPILE_FLAGS -Wall)

list(APPEND H3_COMPILE_FLAGS $<$<CONFIG:Debug>:-gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types>)

if(ENABLE_COVERAGE)
Expand All @@ -107,9 +114,13 @@ if(NOT WIN32)
list(APPEND H3_COMPILE_FLAGS -fsanitize=fuzzer,address,undefined)
list(APPEND H3_LINK_FLAGS -fsanitize=fuzzer,address,undefined)
endif()
endif()

option(WARNINGS_AS_ERRORS "Warnings are treated as errors" OFF)
if(WARNINGS_AS_ERRORS)
option(WARNINGS_AS_ERRORS "Warnings are treated as errors" OFF)
if(WARNINGS_AS_ERRORS)
if(WIN32)
list(APPEND H3_COMPILE_FLAGS /WX)
else()
list(APPEND H3_COMPILE_FLAGS -Werror)
endif()
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/apps/testapps/testCellToLocalIj.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ SUITE(h3ToLocalIj) {

TEST(invalid_negativeIj) {
H3Index index = 0x200f202020202020;
CoordIJ ij = {.i = -14671840, .j = -2147483648};
CoordIJ ij = {.i = -14671840, .j = INT32_MIN};
H3Index out;
t_assert(H3_EXPORT(localIjToCell)(index, &ij, 0, &out) == E_FAILED,
"Negative I and J components fail");
Expand Down
2 changes: 1 addition & 1 deletion src/apps/testapps/testH3Memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void *test_prefix_realloc(void *ptr, size_t size) {

void test_prefix_free(void *ptr) {
actualFreeCalls++;
return free(ptr);
free(ptr);
}

H3Index sunnyvale = 0x89283470c27ffff;
Expand Down
19 changes: 15 additions & 4 deletions src/h3lib/include/mathExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef MATHEXTENSIONS_H
#define MATHEXTENSIONS_H

#include <stdbool.h>
#include <stdint.h>

/**
Expand All @@ -28,12 +29,22 @@
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

/** Evaluates to true if a + b would overflow for int32 */
#define ADD_INT32S_OVERFLOWS(a, b) \
((a) > 0 ? (INT32_MAX - (a) < (b)) : (INT32_MIN - (a) > (b)))
static inline bool ADD_INT32S_OVERFLOWS(int32_t a, int32_t b) {
if (a > 0) {
return INT32_MAX - a < b;
} else {
return INT32_MIN - a > b;
}
}
Comment on lines +32 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of these two changes? Do they actually affect the compiler warnings in some way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for suppressing the following warnings (that are listed in the description):

src/h3lib/lib/coodijk.c:

(236,13): warning C4307: '+': signed integral constant overflow

src/apps/testapps/testMathExtensionsInternal.c:

(81,9): warning C4307: '-': signed integral constant overflow
(82,9): warning C4307: '-': signed integral constant overflow
(83,9): warning C4307: '-': signed integral constant overflow
(84,9): warning C4307: '-': signed integral constant overflow
(85,9): warning C4307: '-': signed integral constant overflow
(86,9): warning C4307: '-': signed integral constant overflow
(87,9): warning C4307: '-': signed integral constant overflow
(88,9): warning C4307: '-': signed integral constant overflow
(89,9): warning C4307: '-': signed integral constant overflow
(90,9): warning C4307: '-': signed integral constant overflow
(91,9): warning C4307: '-': signed integral constant overflow
(92,9): warning C4307: '-': signed integral constant overflow
(93,9): warning C4307: '-': signed integral constant overflow
(94,9): warning C4307: '-': signed integral constant overflow
(95,9): warning C4307: '-': signed integral constant overflow
(96,9): warning C4307: '-': signed integral constant overflow
(97,9): warning C4307: '-': signed integral constant overflow
(98,9): warning C4307: '-': signed integral constant overflow
(99,9): warning C4307: '-': signed integral constant overflow
(100,9): warning C4307: '-': signed integral constant overflow
(101,9): warning C4307: '-': signed integral constant overflow
(102,9): warning C4307: '-': signed integral constant overflow
(103,9): warning C4307: '-': signed integral constant overflow
(104,9): warning C4307: '-': signed integral constant overflow
(105,9): warning C4307: '-': signed integral constant overflow
(106,9): warning C4307: '-': signed integral constant overflow

It seems that MSVC can't process ... ? ... : ... correctly for this warning yet.


/** Evaluates to true if a - b would overflow for int32 */
#define SUB_INT32S_OVERFLOWS(a, b) \
((a) >= 0 ? (INT32_MIN + (a) >= (b)) : (INT32_MAX + (a) + 1 < (b)))
static inline bool SUB_INT32S_OVERFLOWS(int32_t a, int32_t b) {
if (a >= 0) {
return INT32_MIN + a >= b;
} else {
return INT32_MAX + a + 1 < b;
}
}

// Internal functions
int64_t _ipow(int64_t base, int64_t exp);
Expand Down
8 changes: 4 additions & 4 deletions src/h3lib/lib/coordijk.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void _hex2dToCoordIJK(const Vec2d *v, CoordIJK *h) {
x1 = a1 + x2 / 2.0;

// check if we have the center of a hex
m1 = x1;
m2 = x2;
m1 = (int)x1;
m2 = (int)x2;

// otherwise round correctly
r1 = x1 - m1;
Expand Down Expand Up @@ -130,11 +130,11 @@ void _hex2dToCoordIJK(const Vec2d *v, CoordIJK *h) {
{
long long int axisi = h->j / 2;
long long int diff = h->i - axisi;
h->i = h->i - 2.0 * diff;
h->i = (int)(h->i - 2.0 * diff);
} else {
long long int axisi = (h->j + 1) / 2;
long long int diff = h->i - axisi;
h->i = h->i - (2.0 * diff + 1);
h->i = (int)(h->i - (2.0 * diff + 1));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/h3lib/lib/localij.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ H3Error H3_EXPORT(gridPathCellsSize)(H3Index start, H3Index end,
* @param ijk IJK coord struct, modified in place
*/
static void cubeRound(double i, double j, double k, CoordIJK *ijk) {
int ri = round(i);
int rj = round(j);
int rk = round(k);
int ri = (int)round(i);
int rj = (int)round(j);
int rk = (int)round(k);

double iDiff = fabs((double)ri - i);
double jDiff = fabs((double)rj - j);
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载