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

Fix undefined behaviour with negative input in TYPMOD_GET_SRID #152

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions liblwgeom/cunit/cu_libgeom.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ static void test_typmod_macros(void)
rv = TYPMOD_GET_SRID(typmod);
CU_ASSERT_EQUAL(rv, srid);

srid = 999999;
TYPMOD_SET_SRID(typmod,srid);
rv = TYPMOD_GET_SRID(typmod);
CU_ASSERT_EQUAL(rv, srid);

srid = -999999;
TYPMOD_SET_SRID(typmod,srid);
rv = TYPMOD_GET_SRID(typmod);
CU_ASSERT_EQUAL(rv, srid);

srid = SRID_UNKNOWN;
TYPMOD_SET_SRID(typmod,srid);
rv = TYPMOD_GET_SRID(typmod);
Expand Down
2 changes: 1 addition & 1 deletion liblwgeom/liblwgeom.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef enum LWORD_T {
* ZM Flags = Bottom 2 bits.
*/

#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x1FFFFF00)<<3)>>11)
#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
#define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
#define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
#define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
Expand Down