[geos-devel] [GEOS] #869: CommonBits::zeroLowerBits undefined behavior

GEOS geos-trac at osgeo.org
Thu Sep 19 04:34:07 PDT 2019


#869: CommonBits::zeroLowerBits undefined behavior
-------------------------------+---------------------------
 Reporter:  goatbar            |       Owner:  geos-devel@…
     Type:  defect             |      Status:  closed
 Priority:  minor              |   Milestone:  3.6.4
Component:  Default            |     Version:  3.6.2
 Severity:  Unassigned         |  Resolution:  fixed
 Keywords:  UndefinedBehavior  |
-------------------------------+---------------------------

Comment (by goatbar):

 The test I was using when looking at this issue:

 {{{#!cpp
     // zeroLowerBits.
     template<>
     template<>
     void object::test<4>()
     {
         constexpr int64 val = static_cast<int64>(0xffffffffffffffffull);
         ensure_equals(sizeof(val), 8);

         ensure_equals(CommonBits::zeroLowerBits(val, -1), 0);
         ensure_equals(CommonBits::zeroLowerBits(val, 0), 0);
         ensure_equals(CommonBits::zeroLowerBits(val, 1), -2);
         ensure_equals(CommonBits::zeroLowerBits(val, 2), -4);
         ensure_equals(CommonBits::zeroLowerBits(val, 16), -65536);
         ensure_equals(CommonBits::zeroLowerBits(val, 31), -2147483648ll);
         ensure_equals(CommonBits::zeroLowerBits(val, 32), -4294967296ll);
         ensure_equals(CommonBits::zeroLowerBits(val, 62),
 -4611686018427387904ll);
         ensure_equals(static_cast<uint64_t>(CommonBits::zeroLowerBits(val,
 62)), 0xc000000000000000ull);
         ensure_equals(static_cast<uint64_t>(CommonBits::zeroLowerBits(val,
 63)), 0x8000000000000000ull);
         ensure_equals(CommonBits::zeroLowerBits(val, 64), 0);
         ensure_equals(CommonBits::zeroLowerBits(val, 10000), 0);
     }
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/geos/ticket/869#comment:11>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).


More information about the geos-devel mailing list