summaryrefslogtreecommitdiff
path: root/sql/spatial.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/spatial.h')
-rw-r--r--sql/spatial.h33
1 files changed, 30 insertions, 3 deletions
diff --git a/sql/spatial.h b/sql/spatial.h
index 9aaedfe8a20..6df6e37e9b8 100644
--- a/sql/spatial.h
+++ b/sql/spatial.h
@@ -1,5 +1,6 @@
/*
- Copyright (c) 2002, 2010, Oracle and/or its affiliates.
+ Copyright (c) 2002, 2013, Oracle and/or its affiliates.
+ Copyright (c) 2009, 2013, Monty Program Ab.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,7 +29,7 @@ class Gis_read_stream;
const uint SRID_SIZE= 4;
const uint SIZEOF_STORED_DOUBLE= 8;
-const uint POINT_DATA_SIZE= SIZEOF_STORED_DOUBLE*2;
+const uint POINT_DATA_SIZE= (SIZEOF_STORED_DOUBLE * 2);
const uint WKB_HEADER_SIZE= 1+4;
const uint32 GET_SIZE_ERROR= ((uint32) -1);
@@ -334,10 +335,36 @@ protected:
const char *get_mbr_for_points(MBR *mbr, const char *data, uint offset)
const;
- inline bool no_data(const char *cur_data, uint32 data_amount) const
+ /**
+ Check if there're enough data remaining as requested
+
+ @arg cur_data pointer to the position in the binary form
+ @arg data_amount number of points expected
+ @return true if not enough data
+ */
+ inline bool no_data(const char *cur_data, size_t data_amount) const
{
return (cur_data + data_amount > m_data_end);
}
+
+ /**
+ Check if there're enough points remaining as requested
+
+ Need to perform the calculation in logical units, since multiplication
+ can overflow the size data type.
+
+ @arg data pointer to the begining of the points array
+ @arg expected_points number of points expected
+ @arg extra_point_space extra space for each point element in the array
+ @return true if there are not enough points
+ */
+ inline bool not_enough_points(const char *data, uint32 expected_points,
+ uint32 extra_point_space = 0) const
+ {
+ return (m_data_end < data ||
+ (expected_points > ((m_data_end - data) /
+ (POINT_DATA_SIZE + extra_point_space))));
+ }
const char *m_data;
const char *m_data_end;
};