[geos-commits] [SCM] GEOS branch master updated. d60a6649ab6a7db05798afc8f2032fecd0aaa8eb

git at osgeo.org git at osgeo.org
Thu Jan 28 20:05:25 PST 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  d60a6649ab6a7db05798afc8f2032fecd0aaa8eb (commit)
       via  297cf7f62fb1c677d9c69c19cfa333c143e64836 (commit)
       via  d28547cbd289a36e6829528f764b928ef91dc01e (commit)
      from  c03c6856210a8e1cc7c8bb399e8972a6debfedd1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d60a6649ab6a7db05798afc8f2032fecd0aaa8eb
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Jan 28 23:05:14 2021 -0500

    Mark WKTReader methods const

diff --git a/include/geos/io/WKTReader.h b/include/geos/io/WKTReader.h
index a67cb0e..ff222d4 100644
--- a/include/geos/io/WKTReader.h
+++ b/include/geos/io/WKTReader.h
@@ -60,20 +60,20 @@ public:
     //WKTReader();
 
     /**
-     * \brief Inizialize parser with given GeometryFactory.
+     * \brief Initialize parser with given GeometryFactory.
      *
      * Note that all Geometry objects created by the
      * parser will contain a pointer to the given factory
      * so be sure you'll keep the factory alive for the
      * whole WKTReader and created Geometry life.
      */
-    WKTReader(const geom::GeometryFactory& gf);
+    explicit WKTReader(const geom::GeometryFactory& gf);
 
     /** @deprecated in 3.4.0 */
-    WKTReader(const geom::GeometryFactory* gf);
+    explicit WKTReader(const geom::GeometryFactory* gf);
 
     /**
-     * \brief Inizialize parser with default GeometryFactory.
+     * \brief Initialize parser with default GeometryFactory.
      *
      */
     WKTReader();
@@ -81,31 +81,31 @@ public:
     ~WKTReader();
 
     /// Parse a WKT string returning a Geometry
-    std::unique_ptr<geom::Geometry> read(const std::string& wellKnownText);
+    std::unique_ptr<geom::Geometry> read(const std::string& wellKnownText) const;
 
 //	Geometry* read(Reader& reader);	//Not implemented yet
 
 protected:
-    std::unique_ptr<geom::CoordinateSequence> getCoordinates(io::StringTokenizer* tokenizer);
-    double getNextNumber(io::StringTokenizer* tokenizer);
+    std::unique_ptr<geom::CoordinateSequence> getCoordinates(io::StringTokenizer* tokenizer) const;
+    static double getNextNumber(io::StringTokenizer* tokenizer);
     static std::string getNextEmptyOrOpener(io::StringTokenizer* tokenizer, std::size_t& dim);
     static std::string getNextCloserOrComma(io::StringTokenizer* tokenizer);
     static std::string getNextCloser(io::StringTokenizer* tokenizer);
     static std::string getNextWord(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::Geometry> readGeometryTaggedText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::Point> readPointText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::LineString> readLineStringText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::LinearRing> readLinearRingText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::MultiPoint> readMultiPointText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::Polygon> readPolygonText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::MultiLineString> readMultiLineStringText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::MultiPolygon> readMultiPolygonText(io::StringTokenizer* tokenizer);
-    std::unique_ptr<geom::GeometryCollection> readGeometryCollectionText(io::StringTokenizer* tokenizer);
+    std::unique_ptr<geom::Geometry> readGeometryTaggedText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::Point> readPointText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::LineString> readLineStringText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::LinearRing> readLinearRingText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::MultiPoint> readMultiPointText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::Polygon> readPolygonText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::MultiLineString> readMultiLineStringText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::MultiPolygon> readMultiPolygonText(io::StringTokenizer* tokenizer) const;
+    std::unique_ptr<geom::GeometryCollection> readGeometryCollectionText(io::StringTokenizer* tokenizer) const;
 private:
     const geom::GeometryFactory* geometryFactory;
     const geom::PrecisionModel* precisionModel;
 
-    void getPreciseCoordinate(io::StringTokenizer* tokenizer, geom::Coordinate&, std::size_t& dim);
+    void getPreciseCoordinate(io::StringTokenizer* tokenizer, geom::Coordinate&, std::size_t& dim) const;
 
     static bool isNumberNext(io::StringTokenizer* tokenizer);
 };
diff --git a/src/io/WKTReader.cpp b/src/io/WKTReader.cpp
index 3e45940..b380481 100644
--- a/src/io/WKTReader.cpp
+++ b/src/io/WKTReader.cpp
@@ -60,7 +60,7 @@ namespace geos {
 namespace io { // geos.io
 
 std::unique_ptr<Geometry>
-WKTReader::read(const std::string& wellKnownText)
+WKTReader::read(const std::string& wellKnownText) const
 {
     CLocalizer clocale;
     StringTokenizer tokenizer(wellKnownText);
@@ -68,7 +68,7 @@ WKTReader::read(const std::string& wellKnownText)
 }
 
 std::unique_ptr<CoordinateSequence>
-WKTReader::getCoordinates(StringTokenizer* tokenizer)
+WKTReader::getCoordinates(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);
@@ -95,7 +95,7 @@ WKTReader::getCoordinates(StringTokenizer* tokenizer)
 void
 WKTReader::getPreciseCoordinate(StringTokenizer* tokenizer,
                                 Coordinate& coord,
-                                size_t& dim)
+                                size_t& dim) const
 {
     coord.x = getNextNumber(tokenizer);
     coord.y = getNextNumber(tokenizer);
@@ -220,7 +220,7 @@ WKTReader::getNextWord(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<Geometry>
-WKTReader::readGeometryTaggedText(StringTokenizer* tokenizer)
+WKTReader::readGeometryTaggedText(StringTokenizer* tokenizer) const
 {
     std::string type = getNextWord(tokenizer);
     if(type == "POINT") {
@@ -251,7 +251,7 @@ WKTReader::readGeometryTaggedText(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<Point>
-WKTReader::readPointText(StringTokenizer* tokenizer)
+WKTReader::readPointText(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);
@@ -267,21 +267,21 @@ WKTReader::readPointText(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<LineString>
-WKTReader::readLineStringText(StringTokenizer* tokenizer)
+WKTReader::readLineStringText(StringTokenizer* tokenizer) const
 {
     auto&& coords = getCoordinates(tokenizer);
     return geometryFactory->createLineString(std::move(coords));
 }
 
 std::unique_ptr<LinearRing>
-WKTReader::readLinearRingText(StringTokenizer* tokenizer)
+WKTReader::readLinearRingText(StringTokenizer* tokenizer) const
 {
     auto&& coords = getCoordinates(tokenizer);
     return geometryFactory->createLinearRing(std::move(coords));
 }
 
 std::unique_ptr<MultiPoint>
-WKTReader::readMultiPointText(StringTokenizer* tokenizer)
+WKTReader::readMultiPointText(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);
@@ -352,7 +352,7 @@ WKTReader::readMultiPointText(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<Polygon>
-WKTReader::readPolygonText(StringTokenizer* tokenizer)
+WKTReader::readPolygonText(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);
@@ -372,7 +372,7 @@ WKTReader::readPolygonText(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<MultiLineString>
-WKTReader::readMultiLineStringText(StringTokenizer* tokenizer)
+WKTReader::readMultiLineStringText(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);
@@ -390,7 +390,7 @@ WKTReader::readMultiLineStringText(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<MultiPolygon>
-WKTReader::readMultiPolygonText(StringTokenizer* tokenizer)
+WKTReader::readMultiPolygonText(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);
@@ -408,7 +408,7 @@ WKTReader::readMultiPolygonText(StringTokenizer* tokenizer)
 }
 
 std::unique_ptr<GeometryCollection>
-WKTReader::readGeometryCollectionText(StringTokenizer* tokenizer)
+WKTReader::readGeometryCollectionText(StringTokenizer* tokenizer) const
 {
     std::size_t dim = 2;
     std::string nextToken = getNextEmptyOrOpener(tokenizer, dim);

commit 297cf7f62fb1c677d9c69c19cfa333c143e64836
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Jan 28 23:00:11 2021 -0500

    Quiet warnings in WKTReader

diff --git a/src/io/WKTReader.cpp b/src/io/WKTReader.cpp
index bae2b49..3e45940 100644
--- a/src/io/WKTReader.cpp
+++ b/src/io/WKTReader.cpp
@@ -78,7 +78,7 @@ WKTReader::getCoordinates(StringTokenizer* tokenizer)
 
     Coordinate coord;
     getPreciseCoordinate(tokenizer, coord, dim);
-    auto coordinates = detail::make_unique<CoordinateArraySequence>(0, dim);
+    auto coordinates = detail::make_unique<CoordinateArraySequence>(0u, dim);
     coordinates->add(coord);
 
     nextToken = getNextCloserOrComma(tokenizer);
@@ -200,10 +200,10 @@ WKTReader::getNextWord(StringTokenizer* tokenizer)
         throw  ParseException("Expected word but encountered number", tokenizer->getNVal());
     case StringTokenizer::TT_WORD: {
         std::string word = tokenizer->getSVal();
-        int i = static_cast<int>(word.size());
-
-        while(--i >= 0) {
-            word[i] = static_cast<char>(toupper(word[i]));
+        for (char& c : word) {
+            // Avoid UB if c is not representable as unsigned char
+            // https://en.cppreference.com/w/cpp/string/byte/toupper
+            c = static_cast<char>(toupper(static_cast<unsigned char>(c)));
         }
         return word;
     }

commit d28547cbd289a36e6829528f764b928ef91dc01e
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Jan 28 20:43:38 2021 -0500

    Read unsigned integers in WKBReader
    
    OGC WKB spec specifies that the integers are unsigned. Use of signed
    integers is probably a carryover from Java, which does not have unsigned
    integers. Clear type conversion warnings in WKBReader and use C++11
    int64_t type.

diff --git a/benchmarks/ClassSizes.cpp b/benchmarks/ClassSizes.cpp
index 0a7f3b9..86b2592 100644
--- a/benchmarks/ClassSizes.cpp
+++ b/benchmarks/ClassSizes.cpp
@@ -76,6 +76,6 @@ main()
     check(triangulate::quadedge::QuadEdge);
     check(triangulate::quadedge::QuadEdgeQuartet);
     check(triangulate::quadedge::Vertex);
-    check(int64);
+    check(int64_t);
 }
 
diff --git a/include/geos/constants.h b/include/geos/constants.h
index 7d4bb61..877a05c 100644
--- a/include/geos/constants.h
+++ b/include/geos/constants.h
@@ -31,9 +31,6 @@ typedef __int64 int64;
 #include <limits>
 #include <cinttypes>
 
-
-typedef int64_t int64;
-
 namespace geos {
 
 constexpr double MATH_PI = 3.14159265358979323846;
diff --git a/include/geos/io/ByteOrderDataInStream.h b/include/geos/io/ByteOrderDataInStream.h
index b2530af..58c4ce4 100644
--- a/include/geos/io/ByteOrderDataInStream.h
+++ b/include/geos/io/ByteOrderDataInStream.h
@@ -21,6 +21,7 @@
 #define GEOS_IO_BYTEORDERDATAINSTREAM_H
 
 #include <geos/export.h>
+#include <cstdint>
 
 //#include <geos/io/ParseException.h>
 //#include <geos/io/ByteOrderValues.h>
@@ -50,9 +51,11 @@ public:
 
     unsigned char readByte(); // throws ParseException
 
-    int readInt(); // throws ParseException
+    int32_t readInt(); // throws ParseException
 
-    long readLong(); // throws ParseException
+    uint32_t readUnsigned(); // throws ParseException
+
+    int64_t readLong(); // throws ParseException
 
     double readDouble(); // throws ParseException
 
diff --git a/include/geos/io/ByteOrderDataInStream.inl b/include/geos/io/ByteOrderDataInStream.inl
index 399cbbb..32ab931 100644
--- a/include/geos/io/ByteOrderDataInStream.inl
+++ b/include/geos/io/ByteOrderDataInStream.inl
@@ -61,7 +61,7 @@ ByteOrderDataInStream::readByte() // throws ParseException
     return ret;
 }
 
-INLINE int
+INLINE int32_t
 ByteOrderDataInStream::readInt()
 {
     if(size() < 4) {
@@ -72,14 +72,25 @@ ByteOrderDataInStream::readInt()
     return ret;
 }
 
-INLINE long
+INLINE uint32_t
+ByteOrderDataInStream::readUnsigned()
+{
+    if(size() < 4) {
+        throw ParseException("Unexpected EOF parsing WKB");
+    }
+    auto ret =  ByteOrderValues::getUnsigned(buf , byteOrder);
+    buf += 4;
+    return ret;
+}
+
+INLINE int64_t
 ByteOrderDataInStream::readLong()
 {
     if(size() < 8) {
         throw ParseException("Unexpected EOF parsing WKB");
     }
 
-    auto ret = static_cast<long>(ByteOrderValues::getLong(buf, byteOrder));
+    auto ret = ByteOrderValues::getLong(buf, byteOrder);
     buf += 8;
     return ret;
 }
diff --git a/include/geos/io/ByteOrderValues.h b/include/geos/io/ByteOrderValues.h
index e2d2344..9902001 100644
--- a/include/geos/io/ByteOrderValues.h
+++ b/include/geos/io/ByteOrderValues.h
@@ -21,7 +21,7 @@
 #define GEOS_IO_BYTEORDERVALUES_H
 
 #include <geos/export.h>
-#include <geos/constants.h>
+#include <cstdint>
 
 namespace geos {
 namespace io {
@@ -43,11 +43,14 @@ public:
         ENDIAN_LITTLE = 1
     };
 
-    static int getInt(const unsigned char* buf, int byteOrder);
-    static void putInt(int intValue, unsigned char* buf, int byteOrder);
+    static int32_t getInt(const unsigned char* buf, int byteOrder);
+    static void putInt(int32_t intValue, unsigned char* buf, int byteOrder);
 
-    static int64 getLong(const unsigned char* buf, int byteOrder);
-    static void putLong(int64 longValue, unsigned char* buf, int byteOrder);
+    static uint32_t getUnsigned(const unsigned char* buf, int byteOrder);
+    static void putUnsigned(uint32_t intValue, unsigned char* buf, int byteOrder);
+
+    static int64_t getLong(const unsigned char* buf, int byteOrder);
+    static void putLong(int64_t longValue, unsigned char* buf, int byteOrder);
 
     static double getDouble(const unsigned char* buf, int byteOrder);
     static void putDouble(double doubleValue, unsigned char* buf, int byteOrder);
diff --git a/include/geos/io/WKBReader.h b/include/geos/io/WKBReader.h
index c775a96..d908552 100644
--- a/include/geos/io/WKBReader.h
+++ b/include/geos/io/WKBReader.h
@@ -156,7 +156,7 @@ private:
 
     std::unique_ptr<geom::GeometryCollection> readGeometryCollection();
 
-    std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(int); // throws IOException
+    std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(unsigned int); // throws IOException
 
     void readCoordinate(); // throws IOException
 
diff --git a/include/geos/precision/CommonBits.h b/include/geos/precision/CommonBits.h
index 60954a0..cd34c2a 100644
--- a/include/geos/precision/CommonBits.h
+++ b/include/geos/precision/CommonBits.h
@@ -16,7 +16,7 @@
 #define GEOS_PRECISION_COMMONBITS_H
 
 #include <geos/export.h>
-#include <geos/constants.h> // for int64
+#include <cstdint>
 
 namespace geos {
 namespace precision { // geos.precision
@@ -38,9 +38,9 @@ private:
 
     int commonMantissaBitsCount;
 
-    int64 commonBits;
+    int64_t commonBits;
 
-    int64 commonSignExp;
+    int64_t commonSignExp;
 
 public:
 
@@ -51,7 +51,7 @@ public:
      * @param num
      * @return the bit pattern for the sign and exponent
      */
-    static int64 signExpBits(int64 num);
+    static int64_t signExpBits(int64_t num);
 
     /** \brief
      * This computes the number of common most-significant
@@ -65,7 +65,7 @@ public:
      * @param num2
      * @return the number of common most-significant mantissa bits
      */
-    static int numCommonMostSigMantissaBits(int64 num1, int64 num2);
+    static int numCommonMostSigMantissaBits(int64_t num1, int64_t num2);
 
     /** \brief
      * Zeroes the lower n bits of a bitstring.
@@ -74,7 +74,7 @@ public:
      * @param nBits the number of bits to zero
      * @return the zeroed bitstring
      */
-    static int64 zeroLowerBits(int64 bits, int nBits);
+    static int64_t zeroLowerBits(int64_t bits, int nBits);
 
     /** \brief
      * Extracts the i'th bit of a bitstring.
@@ -83,7 +83,7 @@ public:
      * @param i the bit to extract
      * @return the value of the extracted bit
      */
-    static int getBit(int64 bits, int i);
+    static int getBit(int64_t bits, int i);
 
     CommonBits();
 
diff --git a/src/io/ByteOrderValues.cpp b/src/io/ByteOrderValues.cpp
index 8b3f8da..32fecf0 100644
--- a/src/io/ByteOrderValues.cpp
+++ b/src/io/ByteOrderValues.cpp
@@ -31,27 +31,65 @@
 namespace geos {
 namespace io { // geos.io
 
-int
+int32_t
 ByteOrderValues::getInt(const unsigned char* buf, int byteOrder)
 {
     if(byteOrder == ENDIAN_BIG) {
-        return ((int)(buf[0] & 0xff) << 24) |
-               ((int)(buf[1] & 0xff) << 16) |
-               ((int)(buf[2] & 0xff) << 8) |
-               ((int)(buf[3] & 0xff));
+        return ((int32_t)(buf[0] & 0xff) << 24) |
+               ((int32_t)(buf[1] & 0xff) << 16) |
+               ((int32_t)(buf[2] & 0xff) << 8) |
+               ((int32_t)(buf[3] & 0xff));
     }
     else { // ENDIAN_LITTLE
         assert(byteOrder == ENDIAN_LITTLE);
 
-        return ((int)(buf[3] & 0xff) << 24) |
-               ((int)(buf[2] & 0xff) << 16) |
-               ((int)(buf[1] & 0xff) << 8) |
-               ((int)(buf[0] & 0xff));
+        return ((int32_t)(buf[3] & 0xff) << 24) |
+               ((int32_t)(buf[2] & 0xff) << 16) |
+               ((int32_t)(buf[1] & 0xff) << 8) |
+               ((int32_t)(buf[0] & 0xff));
+    }
+}
+
+uint32_t
+ByteOrderValues::getUnsigned(const unsigned char* buf, int byteOrder)
+{
+    if(byteOrder == ENDIAN_BIG) {
+        return ((uint32_t)(buf[0] & 0xff) << 24) |
+               ((uint32_t)(buf[1] & 0xff) << 16) |
+               ((uint32_t)(buf[2] & 0xff) << 8) |
+               ((uint32_t)(buf[3] & 0xff));
+    }
+    else { // ENDIAN_LITTLE
+        assert(byteOrder == ENDIAN_LITTLE);
+
+        return ((uint32_t)(buf[3] & 0xff) << 24) |
+               ((uint32_t)(buf[2] & 0xff) << 16) |
+               ((uint32_t)(buf[1] & 0xff) << 8) |
+               ((uint32_t)(buf[0] & 0xff));
+    }
+}
+
+void
+ByteOrderValues::putInt(int32_t intValue, unsigned char* buf, int byteOrder)
+{
+    if(byteOrder == ENDIAN_BIG) {
+        buf[0] = (unsigned char)(intValue >> 24);
+        buf[1] = (unsigned char)(intValue >> 16);
+        buf[2] = (unsigned char)(intValue >> 8);
+        buf[3] = (unsigned char) intValue;
+    }
+    else { // ENDIAN_LITTLE
+        assert(byteOrder == ENDIAN_LITTLE);
+
+        buf[3] = (unsigned char)(intValue >> 24);
+        buf[2] = (unsigned char)(intValue >> 16);
+        buf[1] = (unsigned char)(intValue >> 8);
+        buf[0] = (unsigned char) intValue;
     }
 }
 
 void
-ByteOrderValues::putInt(int intValue, unsigned char* buf, int byteOrder)
+ByteOrderValues::putUnsigned(uint32_t intValue, unsigned char* buf, int byteOrder)
 {
     if(byteOrder == ENDIAN_BIG) {
         buf[0] = (unsigned char)(intValue >> 24);
@@ -69,37 +107,37 @@ ByteOrderValues::putInt(int intValue, unsigned char* buf, int byteOrder)
     }
 }
 
-int64
+int64_t
 ByteOrderValues::getLong(const unsigned char* buf, int byteOrder)
 {
     if(byteOrder == ENDIAN_BIG) {
         return
-            (int64)(buf[0]) << 56
-            | (int64)(buf[1] & 0xff) << 48
-            | (int64)(buf[2] & 0xff) << 40
-            | (int64)(buf[3] & 0xff) << 32
-            | (int64)(buf[4] & 0xff) << 24
-            | (int64)(buf[5] & 0xff) << 16
-            | (int64)(buf[6] & 0xff) <<  8
-            | (int64)(buf[7] & 0xff);
+            (int64_t)(buf[0]) << 56
+            | (int64_t)(buf[1] & 0xff) << 48
+            | (int64_t)(buf[2] & 0xff) << 40
+            | (int64_t)(buf[3] & 0xff) << 32
+            | (int64_t)(buf[4] & 0xff) << 24
+            | (int64_t)(buf[5] & 0xff) << 16
+            | (int64_t)(buf[6] & 0xff) <<  8
+            | (int64_t)(buf[7] & 0xff);
     }
     else { // ENDIAN_LITTLE
         assert(byteOrder == ENDIAN_LITTLE);
 
         return
-            (int64)(buf[7]) << 56
-            | (int64)(buf[6] & 0xff) << 48
-            | (int64)(buf[5] & 0xff) << 40
-            | (int64)(buf[4] & 0xff) << 32
-            | (int64)(buf[3] & 0xff) << 24
-            | (int64)(buf[2] & 0xff) << 16
-            | (int64)(buf[1] & 0xff) <<  8
-            | (int64)(buf[0] & 0xff);
+            (int64_t)(buf[7]) << 56
+            | (int64_t)(buf[6] & 0xff) << 48
+            | (int64_t)(buf[5] & 0xff) << 40
+            | (int64_t)(buf[4] & 0xff) << 32
+            | (int64_t)(buf[3] & 0xff) << 24
+            | (int64_t)(buf[2] & 0xff) << 16
+            | (int64_t)(buf[1] & 0xff) <<  8
+            | (int64_t)(buf[0] & 0xff);
     }
 }
 
 void
-ByteOrderValues::putLong(int64 longValue, unsigned char* buf, int byteOrder)
+ByteOrderValues::putLong(int64_t longValue, unsigned char* buf, int byteOrder)
 {
     if(byteOrder == ENDIAN_BIG) {
         buf[0] = (unsigned char)(longValue >> 56);
@@ -128,7 +166,7 @@ ByteOrderValues::putLong(int64 longValue, unsigned char* buf, int byteOrder)
 double
 ByteOrderValues::getDouble(const unsigned char* buf, int byteOrder)
 {
-    int64 longValue = getLong(buf, byteOrder);
+    int64_t longValue = getLong(buf, byteOrder);
     double ret;
     std::memcpy(&ret, &longValue, sizeof(double));
     return ret;
@@ -137,7 +175,7 @@ ByteOrderValues::getDouble(const unsigned char* buf, int byteOrder)
 void
 ByteOrderValues::putDouble(double doubleValue, unsigned char* buf, int byteOrder)
 {
-    int64 longValue;
+    int64_t longValue;
     std::memcpy(&longValue, &doubleValue, sizeof(double));
 #if DEBUG_BYTEORDER_VALUES
     std::cout << "ByteOrderValues::putDouble(" << doubleValue <<
diff --git a/src/io/WKBReader.cpp b/src/io/WKBReader.cpp
index 66d1613..f1b2952 100644
--- a/src/io/WKBReader.cpp
+++ b/src/io/WKBReader.cpp
@@ -67,7 +67,7 @@ WKBReader::printHEX(std::istream& is, std::ostream& os)
 
     char each = 0;
     while(is.read(&each, 1)) {
-        const unsigned char c = each;
+        const unsigned char c = static_cast<unsigned char>(each);
         int low = (c & 0x0F);
         int high = (c >> 4);
         os << hex[high] << hex[low];
@@ -157,7 +157,7 @@ WKBReader::readHEX(std::istream& is)
         const unsigned char result_low = ASCIIHexToUChar(low);
 
         const unsigned char value =
-            static_cast<char>((result_high << 4) + result_low);
+            static_cast<unsigned char>((result_high << 4) + result_low);
 
 #if DEBUG_HEX_READER
         std::size_t << "HEX " << high << low << " -> DEC " << (int)value << std::endl;
@@ -177,7 +177,7 @@ WKBReader::read(std::istream& is)
     auto size = is.tellg();
     is.seekg(0, std::ios::beg);
 
-    std::vector<unsigned char> buf(size);
+    std::vector<unsigned char> buf(static_cast<size_t>(size));
     is.read((char*) buf.data(), size);
 
     return read(buf.data(), buf.size());
@@ -208,13 +208,13 @@ WKBReader::readGeometry()
         dis.setOrder(ByteOrderValues::ENDIAN_BIG);
     }
 
-    int typeInt = dis.readInt();
+    uint32_t typeInt = dis.readUnsigned();
     /* Pick up both ISO and SFSQL geometry type */
-    int geometryType = (typeInt & 0xffff) % 1000;
+    uint32_t geometryType = (typeInt & 0xffff) % 1000;
     /* ISO type range 1000 is Z, 2000 is M, 3000 is ZM */
-    int isoTypeRange = (typeInt & 0xffff) / 1000;
-    int isoHasZ = (isoTypeRange == 1) || (isoTypeRange == 3);
-    int isoHasM = (isoTypeRange == 2) || (isoTypeRange == 3);
+    uint32_t isoTypeRange = (typeInt & 0xffff) / 1000;
+    bool isoHasZ = (isoTypeRange == 1) || (isoTypeRange == 3);
+    bool isoHasM = (isoTypeRange == 2) || (isoTypeRange == 3);
     /* SFSQL high bit flag for Z, next bit for M */
     int sfsqlHasZ = (typeInt & 0x80000000) != 0;
     int sfsqlHasM = (typeInt & 0x40000000) != 0;
@@ -309,7 +309,7 @@ WKBReader::readPoint()
 std::unique_ptr<LineString>
 WKBReader::readLineString()
 {
-    int size = dis.readInt();
+    uint32_t size = dis.readUnsigned();
 #if DEBUG_WKB_READER
     std::size_t << "WKB npoints: " << size << std::endl;
 #endif
@@ -320,7 +320,7 @@ WKBReader::readLineString()
 std::unique_ptr<LinearRing>
 WKBReader::readLinearRing()
 {
-    int size = dis.readInt();
+    uint32_t size = dis.readUnsigned();
 #if DEBUG_WKB_READER
     std::size_t << "WKB npoints: " << size << std::endl;
 #endif
@@ -331,7 +331,7 @@ WKBReader::readLinearRing()
 std::unique_ptr<Polygon>
 WKBReader::readPolygon()
 {
-    int numRings = dis.readInt();
+    uint32_t numRings = dis.readUnsigned();
 
 #if DEBUG_WKB_READER
     std::size_t << "WKB numRings: " << numRings << std::endl;
@@ -348,7 +348,7 @@ WKBReader::readPolygon()
 
     if(numRings > 1) {
         std::vector<std::unique_ptr<LinearRing>> holes(numRings - 1);
-        for(int i = 0; i < numRings - 1; i++) {
+        for(uint32_t i = 0; i < numRings - 1; i++) {
             holes[i] = readLinearRing();
         }
 
@@ -360,10 +360,10 @@ WKBReader::readPolygon()
 std::unique_ptr<MultiPoint>
 WKBReader::readMultiPoint()
 {
-    int numGeoms = dis.readInt();
+    uint32_t numGeoms = dis.readUnsigned();
     std::vector<std::unique_ptr<Geometry>> geoms(numGeoms);
 
-    for(int i = 0; i < numGeoms; i++) {
+    for(uint32_t i = 0; i < numGeoms; i++) {
         geoms[i] = readGeometry();
         if(!dynamic_cast<Point*>(geoms[i].get())) {
             std::stringstream err;
@@ -378,10 +378,10 @@ WKBReader::readMultiPoint()
 std::unique_ptr<MultiLineString>
 WKBReader::readMultiLineString()
 {
-    int numGeoms = dis.readInt();
+    uint32_t numGeoms = dis.readUnsigned();
     std::vector<std::unique_ptr<Geometry>> geoms(numGeoms);
 
-    for(int i = 0; i < numGeoms; i++) {
+    for(uint32_t i = 0; i < numGeoms; i++) {
         geoms[i] = readGeometry();
         if(!dynamic_cast<LineString*>(geoms[i].get())) {
             std::stringstream err;
@@ -396,10 +396,10 @@ WKBReader::readMultiLineString()
 std::unique_ptr<MultiPolygon>
 WKBReader::readMultiPolygon()
 {
-    int numGeoms = dis.readInt();
+    uint32_t numGeoms = dis.readUnsigned();
     std::vector<std::unique_ptr<Geometry>> geoms(numGeoms);
 
-    for(int i = 0; i < numGeoms; i++) {
+    for(uint32_t i = 0; i < numGeoms; i++) {
         geoms[i] = readGeometry();
         if(!dynamic_cast<Polygon*>(geoms[i].get())) {
             std::stringstream err;
@@ -414,10 +414,10 @@ WKBReader::readMultiPolygon()
 std::unique_ptr<GeometryCollection>
 WKBReader::readGeometryCollection()
 {
-    int numGeoms = dis.readInt();
+    uint32_t numGeoms = dis.readUnsigned();
     std::vector<std::unique_ptr<Geometry>> geoms(numGeoms);
 
-    for(int i = 0; i < numGeoms; i++) {
+    for(uint32_t i = 0; i < numGeoms; i++) {
         geoms[i] = readGeometry();
     }
 
@@ -425,14 +425,14 @@ WKBReader::readGeometryCollection()
 }
 
 std::unique_ptr<CoordinateSequence>
-WKBReader::readCoordinateSequence(int size)
+WKBReader::readCoordinateSequence(uint32_t size)
 {
     unsigned int targetDim = 2 + (hasZ ? 1 : 0);
     auto seq = factory.getCoordinateSequenceFactory()->create(size, targetDim);
     if(targetDim > inputDimension) {
         targetDim = inputDimension;
     }
-    for(int i = 0; i < size; i++) {
+    for(uint32_t i = 0; i < size; i++) {
         readCoordinate();
         for(unsigned int j = 0; j < targetDim; j++) {
             seq->setOrdinate(i, j, ordValues[j]);
diff --git a/src/precision/CommonBits.cpp b/src/precision/CommonBits.cpp
index 69eb6b1..dd93626 100644
--- a/src/precision/CommonBits.cpp
+++ b/src/precision/CommonBits.cpp
@@ -13,22 +13,21 @@
  *
  **********************************************************************/
 
-#include <geos/constants.h> // for int64
 #include <geos/precision/CommonBits.h>
 
 namespace geos {
 namespace precision { // geos.precision
 
 /*static public*/
-int64
-CommonBits::signExpBits(int64 num)
+int64_t
+CommonBits::signExpBits(int64_t num)
 {
     return num >> 52;
 }
 
 /*static public*/
 int
-CommonBits::numCommonMostSigMantissaBits(int64 num1, int64 num2)
+CommonBits::numCommonMostSigMantissaBits(int64_t num1, int64_t num2)
 {
     int count = 0;
     for(int i = 52; i >= 0; i--) {
@@ -41,22 +40,22 @@ CommonBits::numCommonMostSigMantissaBits(int64 num1, int64 num2)
 }
 
 /*static public*/
-int64
-CommonBits::zeroLowerBits(int64 bits, int nBits)
+int64_t
+CommonBits::zeroLowerBits(int64_t bits, int nBits)
 {
     if (nBits >= 64 || nBits < 0) return 0;
     const uint64_t bits_ = static_cast<uint64_t>(bits);
     const uint64_t invMask = (1ull << nBits) - 1;
     const uint64_t mask = ~ invMask;
     const uint64_t zeroed = bits_ & mask;
-    return static_cast<int64>(zeroed);
+    return static_cast<int64_t>(zeroed);
 }
 
 /*static public*/
 int
-CommonBits::getBit(int64 bits, int i)
+CommonBits::getBit(int64_t bits, int i)
 {
-    int64 mask = (1ull << i);
+    int64_t mask = (1ull << i);
     return (bits & mask) != 0 ? 1 : 0;
 }
 
@@ -72,14 +71,14 @@ CommonBits::CommonBits()
 void
 CommonBits::add(double num)
 {
-    int64 numBits = (int64)num;
+    int64_t numBits = (int64_t) num;
     if(isFirst) {
         commonBits = numBits;
         commonSignExp = signExpBits(commonBits);
         isFirst = false;
         return;
     }
-    int64 numSignExp = signExpBits(numBits);
+    int64_t numSignExp = signExpBits(numBits);
     if(numSignExp != commonSignExp) {
         commonBits = 0;
         return;
diff --git a/tests/unit/io/ByteOrderValuesTest.cpp b/tests/unit/io/ByteOrderValuesTest.cpp
index b867550..22fc3a0 100644
--- a/tests/unit/io/ByteOrderValuesTest.cpp
+++ b/tests/unit/io/ByteOrderValuesTest.cpp
@@ -146,6 +146,37 @@ void object::test<3>
     ensure_equals("getLong little endian", out, in);
 }
 
+// 4 - Read/write an unsigned int
+template<>
+template<>
+void object::test<4>()
+{
+    using geos::io::ByteOrderValues;
+
+    unsigned char buf[4];
+    uint32_t in = 3210000003;
+    uint32_t out;
+
+    ByteOrderValues::putUnsigned(in, buf, ByteOrderValues::ENDIAN_BIG);
+    ensure("putUnsigned big endian[0]", buf[0] == 0xbf);
+    ensure("putUnsigned big endian[1]", buf[1] == 0x54);
+    ensure("putUnsigned big endian[2]", buf[2] == 0xb6);
+    ensure("putUnsigned big endian[3]", buf[3] == 0x83);
+
+    out = ByteOrderValues::getUnsigned(buf,
+                                  geos::io::ByteOrderValues::ENDIAN_BIG);
+    ensure_equals("getInt big endian", out, in);
+
+    ByteOrderValues::putUnsigned(in, buf, geos::io::ByteOrderValues::ENDIAN_LITTLE);
+    ensure("putUnsigned little endian[0]", buf[0] == 0x83);
+    ensure("putUnsigned little endian[1]", buf[1] == 0xb6);
+    ensure("putUnsigned little endian[2]", buf[2] == 0x54);
+    ensure("pUtnsigned little endian[3]", buf[3] == 0xbf);
+
+    out = ByteOrderValues::getUnsigned(buf,
+                                  ByteOrderValues::ENDIAN_LITTLE);
+    ensure_equals("getInt little endian", out, in);
+}
 
 } // namespace tut
 
diff --git a/tests/unit/precision/CommonBitsTest.cpp b/tests/unit/precision/CommonBitsTest.cpp
index 1c06182..9725f57 100644
--- a/tests/unit/precision/CommonBitsTest.cpp
+++ b/tests/unit/precision/CommonBitsTest.cpp
@@ -24,7 +24,7 @@ template<>
 void object::test<1>
 ()
 {
-    constexpr int64 val = 0ull;
+    constexpr int64_t val = 0ull;
     for(int i = 0; i < 64; i++) {
         ensure_equals(CommonBits::getBit(val, i), 0);
     }
@@ -36,7 +36,7 @@ template<>
 void object::test<2>
 ()
 {
-    constexpr int64 val = 0xffffffffffffffffull;
+    constexpr int64_t val = 0xffffffffffffffffull;
     for(int i = 0; i < 64; i++) {
         ensure_equals(CommonBits::getBit(val, i), 1);
     }
@@ -48,7 +48,7 @@ template<>
 void object::test<3>
 ()
 {
-    constexpr int64 val = 0xffffffff00000000ull;
+    constexpr int64_t val = 0xffffffff00000000ull;
     ensure_equals(CommonBits::getBit(val, 0), 0);
     ensure_equals(CommonBits::getBit(val, 63), 1);
 }
@@ -58,7 +58,7 @@ template<>
 template<>
 void object::test<4>()
 {
-    constexpr int64 val = static_cast<int64>(0xffffffffffffffffull);
+    constexpr int64_t val = static_cast<int64_t>(0xffffffffffffffffull);
     ensure_equals(sizeof(val), 8u);
 
     ensure_equals(CommonBits::zeroLowerBits(val, -1), 0);

-----------------------------------------------------------------------

Summary of changes:
 benchmarks/ClassSizes.cpp                 |  2 +-
 include/geos/constants.h                  |  3 -
 include/geos/io/ByteOrderDataInStream.h   |  7 ++-
 include/geos/io/ByteOrderDataInStream.inl | 17 +++++-
 include/geos/io/ByteOrderValues.h         | 13 ++--
 include/geos/io/WKBReader.h               |  2 +-
 include/geos/io/WKTReader.h               | 34 +++++------
 include/geos/precision/CommonBits.h       | 14 ++---
 src/io/ByteOrderValues.cpp                | 98 +++++++++++++++++++++----------
 src/io/WKBReader.cpp                      | 44 +++++++-------
 src/io/WKTReader.cpp                      | 34 +++++------
 src/precision/CommonBits.cpp              | 21 ++++---
 tests/unit/io/ByteOrderValuesTest.cpp     | 31 ++++++++++
 tests/unit/precision/CommonBitsTest.cpp   |  8 +--
 14 files changed, 205 insertions(+), 123 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list