Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geohash_point_as_int: Fix undefined behaviour in shift operation #148

Closed
wants to merge 1 commit into from

Conversation

Algunenano
Copy link
Member

Fixing undefined behaviour in test_geohash_point_as_int:

Running test 'test_geohash_point_as_int' in suite 'computational_geometry'.
lwalgorithm.c:669:18: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

0x0001 is a signed int so shifting it 31 bits is undefined. 0x00001u is unsigned so the bit shift is ok.

Fixing undefined behaviour in test_geohash_point_as_int:
Running test 'test_geohash_point_as_int' in suite
'computational_geometry'.lwalgorithm.c:669:18: runtime error: left shift
of 1 by         31 places cannot be represented in type 'int'

Patch by Raul Marin (Carto)
@strk
Copy link
Member

strk commented Oct 4, 2017 via email

@Algunenano
Copy link
Member Author

I'm running on x86_64 with sanitizer flags: -fsanitize=undefined in this case.

It should be possible to add some flags and check them (depending on the configuration it will, or not, stop the program). Not sure if these flags are available in gcc 4.8.4 though, but I can confirm it works in gcc 7.2.0 and clang 5.0.0.

@pramsey
Copy link
Member

pramsey commented Oct 4, 2017

Looks like we could do that trick on travis w/ the right toolchain https://docs.travis-ci.com/user/languages/c/

@strk
Copy link
Member

strk commented Oct 4, 2017 via email

@strk
Copy link
Member

strk commented Oct 6, 2017

Trac ticket corresponding to this PR is ?

@Algunenano
Copy link
Member Author

Sorry, it's here: https://trac.osgeo.org/postgis/ticket/3875

@pramsey pramsey closed this Oct 6, 2017
@Algunenano Algunenano deleted the geohash_shift branch November 15, 2019 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants