Ticket #1335 (closed defect: fixed)

Opened 18 months ago

Last modified 18 months ago

[PATCH] ST_AddPoint returns incorrect result on Linux

Reported by: realityexists Owned by: pramsey
Priority: critical Milestone: PostGIS 2.0.0
Component: postgis Version: trunk
Keywords: Cc: rouault

Description

Running PostGIS 2.0.0 r8251 on Ubuntu 11.04 with PostgreSQL 9.1.1.

SELECT ST_AsText(ST_AddPoint(
  ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326),
  ST_GeomFromText('POINT(10 10)', 4326),
  0));

returns "LINESTRING(10 10,20 20,20 20,40 40)"

PostGIS_FullVersion(): "POSTGIS="2.0.0SVN" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.6.3, released 2009/11/19" LIBXML="2.7.8" USE_STATS"

The latest Windows build (r8242) still returns the correct result ("LINESTRING(10 10,20 20,30 30,40 40)").

Attachments

ticket_1335.patch Download (0.9 KB) - added by rouault 18 months ago.

Change History

Changed 18 months ago by pramsey

Correct answer here on OSX 10.6 x86_64. How many bits on your Linux system?

Changed 18 months ago by realityexists

32

Changed 18 months ago by darkblueb


32 bit Debian Linux, Intel, Postgres 9.1.1, Postgis some prev trunk (?)

db_20b=# SELECT ST_AsText(ST_AddPoint( db_20b(# ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), db_20b(# ST_GeomFromText('POINT(10 10)', 4326), db_20b(# 0));

st_astext


LINESTRING(10 10,20 20,20 20,40 40)

(1 row)

================================================================ 32bit Debian Linux, Intel, Postgres 9.1.1, rebuilt trunk v8251

db_20b=# SELECT ST_AsText(ST_AddPoint( db_20b(# ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), db_20b(# ST_GeomFromText('POINT(10 10)', 4326), db_20b(# 0));

st_astext


LINESTRING(10 10,20 20,20 20,40 20)

(1 row)

====================================================== 64bit Linux, Intel, Postgres 9.0.5, Postgis trunk v8251

db_20b=# SELECT ST_AsText(ST_AddPoint( db_20b(# ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), db_20b(# ST_GeomFromText('POINT(10 10)', 4326), db_20b(# 0));

st_astext


LINESTRING(10 10,20 20,30 30,30 30)

(1 row)

Changed 18 months ago by darkblueb

64bit Linux, AMD

psql (9.0.4)
Type "help" for help.

ct_test_09nov11=# select postgis_full_version();

 POSTGIS="1.5.3" GEOS="3.3.0-CAPI-1.7.0" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.8" USE_STATS
(1 row)

ct_test_09nov11=# select st_astext(st_addpoint(
ct_test_09nov11(#    st_geomfromtext( 'linestring(20 20,30 30,40 40)',4326),
ct_test_09nov11(#    st_geomfromtext( 'POINT(10 10)',4326),
ct_test_09nov11(#    0));
              st_astext              
-------------------------------------
 LINESTRING(10 10,20 20,30 30,40 40)
(1 row)

Changed 18 months ago by darkblueb

two queries sequentially gives the same results; interspersing a function call in between gives two *different* results with the same build on the same architecture.

geocoder_ca=# SELECT ST_AsText(ST_AddPoint(
ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326),
ST_GeomFromText('POINT(10 10)', 4326),
0));
              st_astext              
-------------------------------------
 LINESTRING(10 10,20 20,20 20,40 20)
(1 row)

geocoder_ca=# select postgis_full_version();
geocoder_ca=# SELECT ST_AsText(ST_AddPoint(
ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326),
ST_GeomFromText('POINT(10 10)', 4326),
0));
              st_astext              
-------------------------------------
 LINESTRING(10 10,20 20,20 20,40 40)
(1 row)

Changed 18 months ago by rouault

  • cc rouault added

The issue is an incorrect use of memcpy() instead of memmove() because of overlapping source/destination. So the result depends on implementations. I've fixed the addpoint and removepoint cases, but haven't done an extensive review of other potential similar errors.

Changed 18 months ago by rouault

Changed 18 months ago by rouault

  • summary changed from ST_AddPoint returns incorrect result on Linux to [PATCH] ST_AddPoint returns incorrect result on Linux

Changed 18 months ago by darkblueb

patch applied to trunk build here.. appears to work fine - thx EvenR ! --

db_20b=# SELECT ST_AsText(ST_AddPoint( ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), ST_GeomFromText('POINT(10 10)', 4326), 0));

st_astext


LINESTRING(10 10,20 20,30 30,40 40)

(1 row)

db_20b=# select postgis_full_version(); ... db_20b=# SELECT ST_AsText(ST_AddPoint( ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), ST_GeomFromText('POINT(10 10)', 4326), 0));

st_astext


LINESTRING(10 10,20 20,30 30,40 40)

(1 row)

Changed 18 months ago by pramsey

  • status changed from new to closed
  • resolution set to fixed

Thanks! r8257

Note: See TracTickets for help on using tickets.