[shapelib] 01/07: New upstream version 1.4.1
Bas Couwenberg
sebastic at debian.org
Fri Sep 15 18:53:32 UTC 2017
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository shapelib.
commit ec478a070bac2822195f708eaef9157adf15b298
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Fri Sep 15 20:43:25 2017 +0200
New upstream version 1.4.1
---
CMakeLists.txt | 2 +-
ChangeLog | 13 ++-
configure | 22 ++---
configure.ac | 4 +-
contrib/shpgeo.c | 10 +++
shpopen.c | 252 +++++++++++++++++++++++++++++++++----------------------
web/release.html | 6 ++
7 files changed, 196 insertions(+), 113 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e433198..c3ef935 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,7 +111,7 @@ if(UNIX)
endif(UNIX)
set(shp_SOVERSION 1)
-set(shp_VERSION 1.4.0)
+set(shp_VERSION 1.4.1)
set_target_properties(shp
PROPERTIES
SOVERSION ${shp_SOVERSION}
diff --git a/ChangeLog b/ChangeLog
index 3e17b2d..e8fbde5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,17 @@
+2017-09-10 Even Rouault <even.rouault at spatialys.com>
+
+ * shpopen.c: resync with GDAL copy. Make sure to zero terminate all
+ error messages. And fix regression regarding re-writing the last shape
+ of a file (https://trac.osgeo.org/gdal/ticket/7031)
+
+2017-07-10 Even Rouault <even.rouault at spatialys.com>
+
+ * contrib/shpgeo.c: fix compilation on _MSC_VER < 1800 regarding lack
+ of NAN macro.
+
2016-12-09 Even Rouault <even.rouault at spatialys.com>
- * Makefile.am: install web/maptools.css
+ * Makefile.am: add web/maptools.css to EXTRA_DIST
* Shapelib 1.4.0 released
diff --git a/configure b/configure
index 5d8df6f..0ceb379 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for shapelib 1.4.0.
+# Generated by GNU Autoconf 2.69 for shapelib 1.4.1.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -587,8 +587,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='shapelib'
PACKAGE_TARNAME='shapelib'
-PACKAGE_VERSION='1.4.0'
-PACKAGE_STRING='shapelib 1.4.0'
+PACKAGE_VERSION='1.4.1'
+PACKAGE_STRING='shapelib 1.4.1'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -1340,7 +1340,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures shapelib 1.4.0 to adapt to many kinds of systems.
+\`configure' configures shapelib 1.4.1 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1411,7 +1411,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of shapelib 1.4.0:";;
+ short | recursive ) echo "Configuration of shapelib 1.4.1:";;
esac
cat <<\_ACEOF
@@ -1526,7 +1526,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-shapelib configure 1.4.0
+shapelib configure 1.4.1
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1925,7 +1925,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by shapelib $as_me 1.4.0, which was
+It was created by shapelib $as_me 1.4.1, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -2791,7 +2791,7 @@ fi
# Define the identity of the package.
PACKAGE='shapelib'
- VERSION='1.4.0'
+ VERSION='1.4.1'
cat >>confdefs.h <<_ACEOF
@@ -4137,7 +4137,7 @@ unknown)
esac
-SHAPELIB_SO_VERSION=2:1:0
+SHAPELIB_SO_VERSION=2:2:0
ac_ext=c
@@ -17351,7 +17351,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by shapelib $as_me 1.4.0, which was
+This file was extended by shapelib $as_me 1.4.1, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -17408,7 +17408,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-shapelib config.status 1.4.0
+shapelib config.status 1.4.1
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
diff --git a/configure.ac b/configure.ac
index 619d47f..7ec86d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
m4_define(shapelib_version_major, 1)
m4_define(shapelib_version_minor, 4)
-m4_define(shapelib_version_micro, 0)
+m4_define(shapelib_version_micro, 1)
AC_PREREQ(2.62)
AC_INIT(shapelib, shapelib_version_major.shapelib_version_minor.shapelib_version_micro)
@@ -16,7 +16,7 @@ AM_SILENT_RULES([yes])
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
dnl See http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
-AC_SUBST([SHAPELIB_SO_VERSION], [2:1:0])
+AC_SUBST([SHAPELIB_SO_VERSION], [2:2:0])
AC_PROG_CC
AC_PROG_CXX
diff --git a/contrib/shpgeo.c b/contrib/shpgeo.c
index 4d14d3a..3b04b3a 100644
--- a/contrib/shpgeo.c
+++ b/contrib/shpgeo.c
@@ -32,6 +32,10 @@
* use -DPROJ4 to compile in Projection support
*
* $Log: shpgeo.c,v $
+ * Revision 1.16 2017-07-10 18:01:35 erouault
+ * * contrib/shpgeo.c: fix compilation on _MSC_VER < 1800 regarding lack
+ * of NAN macro.
+ *
* Revision 1.15 2016-12-06 21:13:33 erouault
* * configure.ac: change soname to 2:1:0 to be in sync with Debian soname.
* http://bugzilla.maptools.org/show_bug.cgi?id=2628
@@ -99,6 +103,12 @@
#include "shpgeo.h"
+#if defined(_MSC_VER) && _MSC_VER < 1800
+#include <float.h>
+#define INFINITY (DBL_MAX + DBL_MAX)
+#define NAN (INFINITY - INFINITY)
+#endif
+
/* I'm using some shorthand throughout this file
* R+ is a Clockwise Ring and is the positive portion of an object
diff --git a/shpopen.c b/shpopen.c
index 2ace684..f9d28c2 100644
--- a/shpopen.c
+++ b/shpopen.c
@@ -1,5 +1,5 @@
/******************************************************************************
- * $Id: shpopen.c,v 1.75 2016-12-05 12:44:05 erouault Exp $
+ * $Id: shpopen.c,v 1.76 2017-09-10 10:11:36 erouault Exp $
*
* Project: Shapelib
* Purpose: Implementation of core Shapefile read/write functions.
@@ -35,6 +35,11 @@
******************************************************************************
*
* $Log: shpopen.c,v $
+ * Revision 1.76 2017-09-10 10:11:36 erouault
+ * * shpopen.c: resync with GDAL copy. Make sure to zero terminate all
+ * error messages. And fix regression regarding re-writing the last shape
+ * of a file (https://trac.osgeo.org/gdal/ticket/7031)
+ *
* Revision 1.75 2016-12-05 12:44:05 erouault
* * Major overhaul of Makefile build system to use autoconf/automake.
*
@@ -167,7 +172,7 @@
* avoid c++ comments
*
* Revision 1.38 2002/05/07 16:43:39 warmerda
- * Removed debugging printf.
+ * Removed debugging printf()
*
* Revision 1.37 2002/04/10 17:35:22 warmerda
* fixed bug in ring reversal code
@@ -297,7 +302,7 @@
#include <stdio.h>
#include <errno.h>
-SHP_CVSID("$Id: shpopen.c,v 1.75 2016-12-05 12:44:05 erouault Exp $")
+SHP_CVSID("$Id: shpopen.c,v 1.76 2017-09-10 10:11:36 erouault Exp $")
typedef unsigned char uchar;
@@ -461,11 +466,12 @@ void SHPAPI_CALL SHPWriteHeader( SHPHandle psSHP )
if( psSHP->sHooks.FSeek( psSHP->fpSHP, 0, 0 ) != 0
|| psSHP->sHooks.FWrite( abyHeader, 100, 1, psSHP->fpSHP ) != 1 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Failure writing .shp header: %s", strerror(errno) );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
return;
}
@@ -479,11 +485,12 @@ void SHPAPI_CALL SHPWriteHeader( SHPHandle psSHP )
if( psSHP->sHooks.FSeek( psSHP->fpSHX, 0, 0 ) != 0
|| psSHP->sHooks.FWrite( abyHeader, 100, 1, psSHP->fpSHX ) != 1 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Failure writing .shx header: %s", strerror(errno) );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
return;
}
@@ -509,11 +516,12 @@ void SHPAPI_CALL SHPWriteHeader( SHPHandle psSHP )
if( (int)psSHP->sHooks.FWrite( panSHX, sizeof(int32)*2, psSHP->nRecords, psSHP->fpSHX )
!= psSHP->nRecords )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Failure writing .shx contents: %s", strerror(errno) );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
}
free( panSHX );
@@ -671,14 +679,12 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
pabyBuf = (uchar *) malloc(100);
psSHP->sHooks.FRead( pabyBuf, 100, 1, psSHP->fpSHP );
- psSHP->nFileSize = ((unsigned int)pabyBuf[24] * 256 * 256 * 256
- + (unsigned int)pabyBuf[25] * 256 * 256
- + (unsigned int)pabyBuf[26] * 256
- + (unsigned int)pabyBuf[27]);
- if( psSHP->nFileSize < 0xFFFFFFFFU / 2 )
+ psSHP->nFileSize = ((unsigned int)pabyBuf[24]<<24)|(pabyBuf[25]<<16)|
+ (pabyBuf[26]<<8)|pabyBuf[27];
+ if( psSHP->nFileSize < UINT_MAX / 2 )
psSHP->nFileSize *= 2;
else
- psSHP->nFileSize = 0xFFFFFFFEU;
+ psSHP->nFileSize = (UINT_MAX / 2) * 2;
/* -------------------------------------------------------------------- */
/* Read SHX file Header info */
@@ -692,26 +698,28 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
psSHP->sHooks.Error( ".shx file is unreadable, or corrupt." );
psSHP->sHooks.FClose( psSHP->fpSHP );
psSHP->sHooks.FClose( psSHP->fpSHX );
+ free( pabyBuf );
free( psSHP );
return( NULL );
}
- psSHP->nRecords = pabyBuf[27] + pabyBuf[26] * 256
- + pabyBuf[25] * 256 * 256 + (pabyBuf[24] & 0x7F) * 256 * 256 * 256;
+ psSHP->nRecords = pabyBuf[27]|(pabyBuf[26]<<8)|(pabyBuf[25]<<16)|
+ ((pabyBuf[24] & 0x7F)<<24);
psSHP->nRecords = (psSHP->nRecords - 50) / 4;
psSHP->nShapeType = pabyBuf[32];
if( psSHP->nRecords < 0 || psSHP->nRecords > 256000000 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Record count in .shp header is %d, which seems\n"
"unreasonable. Assuming header is corrupt.",
psSHP->nRecords );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
psSHP->sHooks.FClose( psSHP->fpSHP );
psSHP->sHooks.FClose( psSHP->fpSHX );
free( psSHP );
@@ -791,13 +799,14 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
psSHP->panRecSize == NULL ||
(!bLazySHXLoading && pabyBuf == NULL))
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Not enough memory to allocate requested memory (nRecords=%d).\n"
"Probably broken SHP file",
psSHP->nRecords );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
psSHP->sHooks.FClose( psSHP->fpSHP );
psSHP->sHooks.FClose( psSHP->fpSHX );
if (psSHP->panRecOffset) free( psSHP->panRecOffset );
@@ -817,12 +826,13 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
if( (int) psSHP->sHooks.FRead( pabyBuf, 8, psSHP->nRecords, psSHP->fpSHX )
!= psSHP->nRecords )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Failed to read all values for %d records in .shx file: %s.",
psSHP->nRecords, strerror(errno) );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
/* SHX is short or unreadable for some reason. */
psSHP->sHooks.FClose( psSHP->fpSHP );
@@ -857,6 +867,7 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
char str[128];
snprintf( str, sizeof(str),
"Invalid offset for entity %d", i);
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
SHPClose(psSHP);
@@ -868,6 +879,7 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
char str[128];
snprintf( str, sizeof(str),
"Invalid length for entity %d", i);
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
SHPClose(psSHP);
@@ -1014,14 +1026,12 @@ SHPRestoreSHX ( const char * pszLayer, const char * pszAccess, SAHooks *psHooks
pabyBuf = (uchar *) malloc(100);
psHooks->FRead( pabyBuf, 100, 1, fpSHP );
- nSHPFilesize = ((unsigned int)pabyBuf[24] * 256 * 256 * 256
- + (unsigned int)pabyBuf[25] * 256 * 256
- + (unsigned int)pabyBuf[26] * 256
- + (unsigned int)pabyBuf[27]);
- if( nSHPFilesize < 0xFFFFFFFFU / 2 )
+ nSHPFilesize = ((unsigned int)pabyBuf[24]<<24)|(pabyBuf[25]<<16)|
+ (pabyBuf[26]<<8)|pabyBuf[27];
+ if( nSHPFilesize < UINT_MAX / 2 )
nSHPFilesize *= 2;
else
- nSHPFilesize = 0xFFFFFFFEU;
+ nSHPFilesize = (UINT_MAX / 2) * 2;
snprintf( pszFullname, nFullnameLen, "%s.shx", pszBasename );
fpSHX = psHooks->FOpen( pszFullname, pszSHXAccess );
@@ -1074,11 +1084,7 @@ SHPRestoreSHX ( const char * pszLayer, const char * pszAccess, SAHooks *psHooks
}
else
{
- nMessageLen = strlen( pszBasename ) * 2 + 256;
- pszMessage = (char *) malloc( nMessageLen );
- snprintf( pszMessage, nMessageLen, "Error parsing .shp to restore .shx" );
- psHooks->Error( pszMessage );
- free( pszMessage );
+ psHooks->Error( "Error parsing .shp to restore .shx" );
psHooks->FClose( fpSHX );
psHooks->FClose( fpSHP );
@@ -1277,7 +1283,12 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
fpSHP = psHooks->FOpen(pszFullname, "wb" );
if( fpSHP == NULL )
{
- psHooks->Error( "Failed to create file .shp file." );
+ char szErrorMsg[200];
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
+ "Failed to create file %s: %s",
+ pszFullname, strerror(errno) );
+ psHooks->Error( szErrorMsg );
+
goto error;
}
@@ -1285,7 +1296,11 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
fpSHX = psHooks->FOpen(pszFullname, "wb" );
if( fpSHX == NULL )
{
- psHooks->Error( "Failed to create file .shx file." );
+ char szErrorMsg[200];
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
+ "Failed to create file %s: %s",
+ pszFullname, strerror(errno) );
+ psHooks->Error( szErrorMsg );
goto error;
}
@@ -1323,11 +1338,12 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
/* -------------------------------------------------------------------- */
if( psHooks->FWrite( abyHeader, 100, 1, fpSHP ) != 1 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Failed to write .shp header: %s", strerror(errno) );
- psHooks->Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psHooks->Error( szErrorMsg );
goto error;
}
@@ -1341,11 +1357,12 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
if( psHooks->FWrite( abyHeader, 100, 1, fpSHX ) != 1 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Failure writing .shx header: %s", strerror(errno) );
- psHooks->Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psHooks->Error( szErrorMsg );
goto error;
}
@@ -1515,24 +1532,26 @@ SHPCreateObject( int nSHPType, int nShapeId, int nParts,
/* -------------------------------------------------------------------- */
if( nVertices > 0 )
{
- psObject->padfX = (double *) calloc(sizeof(double),nVertices);
- psObject->padfY = (double *) calloc(sizeof(double),nVertices);
- psObject->padfZ = (double *) calloc(sizeof(double),nVertices);
- psObject->padfM = (double *) calloc(sizeof(double),nVertices);
-
- for( i = 0; i < nVertices; i++ )
- {
- if( padfX != NULL )
- psObject->padfX[i] = padfX[i];
- if( padfY != NULL )
- psObject->padfY[i] = padfY[i];
- if( padfZ != NULL && bHasZ )
- psObject->padfZ[i] = padfZ[i];
- if( padfM != NULL && bHasM )
- psObject->padfM[i] = padfM[i];
- }
+ size_t nSize = sizeof(double) * nVertices;
+ psObject->padfX = (double *) padfX ? malloc(nSize) :
+ calloc(sizeof(double),nVertices);
+ psObject->padfY = (double *) padfY ? malloc(nSize) :
+ calloc(sizeof(double),nVertices);
+ psObject->padfZ = (double *) padfZ && bHasZ ? malloc(nSize) :
+ calloc(sizeof(double),nVertices);
+ psObject->padfM = (double *) padfM && bHasM ? malloc(nSize) :
+ calloc(sizeof(double),nVertices);
+ if( padfX != NULL )
+ memcpy(psObject->padfX, padfX, nSize);
+ if( padfY != NULL )
+ memcpy(psObject->padfY, padfY, nSize);
+ if( padfZ != NULL && bHasZ )
+ memcpy(psObject->padfZ, padfZ, nSize);
if( padfM != NULL && bHasM )
+ {
+ memcpy(psObject->padfM, padfM, nSize);
psObject->bMeasureIsUsed = TRUE;
+ }
}
/* -------------------------------------------------------------------- */
@@ -1576,7 +1595,8 @@ SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
int i;
uchar *pabyRec;
int32 i32;
- int bExtendFile = FALSE;
+ int bAppendToLastRecord = FALSE;
+ int bAppendToFile = FALSE;
psSHP->bUpdated = TRUE;
@@ -1864,24 +1884,32 @@ SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
/* -------------------------------------------------------------------- */
/* Establish where we are going to put this record. If we are */
-/* rewriting and existing record, and it will fit, then put it */
-/* back where the original came from. Otherwise write at the end. */
+/* rewriting the last record of the file, then we can update it in */
+/* place. Otherwise if rewriting an existing record, and it will */
+/* fit, then put it back where the original came from. Otherwise */
+/* write at the end. */
/* -------------------------------------------------------------------- */
- if( nShapeId == -1 || psSHP->panRecSize[nShapeId] < nRecordSize-8 )
+ if( nShapeId != -1 && psSHP->panRecOffset[nShapeId] +
+ psSHP->panRecSize[nShapeId] + 8 == psSHP->nFileSize )
+ {
+ nRecordOffset = psSHP->panRecOffset[nShapeId];
+ bAppendToLastRecord = TRUE;
+ }
+ else if( nShapeId == -1 || psSHP->panRecSize[nShapeId] < nRecordSize-8 )
{
- unsigned int nExpectedSize = psSHP->nFileSize + nRecordSize;
- if( nExpectedSize < psSHP->nFileSize ) // due to unsigned int overflow
+ if( psSHP->nFileSize > UINT_MAX - nRecordSize)
{
char str[128];
snprintf( str, sizeof(str), "Failed to write shape object. "
"File size cannot reach %u + %u.",
psSHP->nFileSize, nRecordSize );
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
free( pabyRec );
return -1;
}
- bExtendFile = TRUE;
+ bAppendToFile = TRUE;
nRecordOffset = psSHP->nFileSize;
}
else
@@ -1909,24 +1937,26 @@ SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
/* -------------------------------------------------------------------- */
if( psSHP->sHooks.FSeek( psSHP->fpSHP, nRecordOffset, 0 ) != 0 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Error in psSHP->sHooks.FSeek() while writing object to .shp file: %s",
strerror(errno) );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
free( pabyRec );
return -1;
}
if( psSHP->sHooks.FWrite( pabyRec, nRecordSize, 1, psSHP->fpSHP ) < 1 )
{
- char szError[200];
+ char szErrorMsg[200];
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Error in psSHP->sHooks.FWrite() while writing object of %u bytes to .shp file: %s",
nRecordSize, strerror(errno) );
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
free( pabyRec );
return -1;
@@ -1934,7 +1964,11 @@ SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
free( pabyRec );
- if( bExtendFile )
+ if( bAppendToLastRecord )
+ {
+ psSHP->nFileSize = psSHP->panRecOffset[nShapeId] + nRecordSize;
+ }
+ else if( bAppendToFile )
{
if( nShapeId == -1 )
nShapeId = psSHP->nRecords++;
@@ -2072,6 +2106,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf( str, sizeof(str),
"Error in fseek()/fread() reading object from .shx file at offset %d",
100 + 8 * hEntity);
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
return NULL;
@@ -2084,6 +2119,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
char str[128];
snprintf( str, sizeof(str),
"Invalid offset for entity %d", hEntity);
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
return NULL;
@@ -2093,6 +2129,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
char str[128];
snprintf( str, sizeof(str),
"Invalid length for entity %d", hEntity);
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
return NULL;
@@ -2116,41 +2153,45 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
nNewBufSize = INT_MAX;
/* Before allocating too much memory, check that the file is big enough */
- if( nEntitySize >= 10 * 1024 * 1024 &&
- (psSHP->panRecOffset[hEntity] >= psSHP->nFileSize ||
- (unsigned int)nEntitySize > psSHP->nFileSize - psSHP->panRecOffset[hEntity]) )
+ /* and do not trust the file size in the header the first time we */
+ /* need to allocate more than 10 MB */
+ if( nNewBufSize >= 10 * 1024 * 1024 &&
+ psSHP->nBufSize < 10 * 1024 * 1024 )
{
- /* We do as is we didn't trust the file size in the header */
SAOffset nFileSize;
psSHP->sHooks.FSeek( psSHP->fpSHP, 0, 2 );
nFileSize = psSHP->sHooks.FTell(psSHP->fpSHP);
- if( nFileSize >= 0xFFFFFFFFU )
- psSHP->nFileSize = 0xFFFFFFFFU;
+ if( nFileSize >= UINT_MAX )
+ psSHP->nFileSize = UINT_MAX;
else
psSHP->nFileSize = (unsigned int)nFileSize;
+ }
- if( psSHP->panRecOffset[hEntity] >= psSHP->nFileSize ||
- (unsigned int)nEntitySize > psSHP->nFileSize - psSHP->panRecOffset[hEntity] )
- {
- char str[128];
- snprintf( str, sizeof(str),
- "Error in fread() reading object of size %d at offset %u from .shp file",
- nEntitySize, psSHP->panRecOffset[hEntity] );
+ if( psSHP->panRecOffset[hEntity] >= psSHP->nFileSize ||
+ /* We should normally use nEntitySize instead of*/
+ /* psSHP->panRecSize[hEntity] in the below test, but because of */
+ /* the case of non conformant .shx files detailed a bit below, */
+ /* let be more tolerant */
+ psSHP->panRecSize[hEntity] > psSHP->nFileSize - psSHP->panRecOffset[hEntity] )
+ {
+ char str[128];
+ snprintf( str, sizeof(str),
+ "Error in fread() reading object of size %d at offset %u from .shp file",
+ nEntitySize, psSHP->panRecOffset[hEntity] );
+ str[sizeof(str)-1] = '\0';
- psSHP->sHooks.Error( str );
- return NULL;
- }
+ psSHP->sHooks.Error( str );
+ return NULL;
}
pabyRecNew = (uchar *) SfRealloc(psSHP->pabyRec,nNewBufSize);
if (pabyRecNew == NULL)
{
- char szError[200];
-
- snprintf( szError, sizeof(szError),
+ snprintf( szErrorMsg, sizeof(szErrorMsg),
"Not enough memory to allocate requested memory (nNewBufSize=%d). "
"Probably broken SHP file", nNewBufSize);
- psSHP->sHooks.Error( szError );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
+ psSHP->sHooks.Error( szErrorMsg );
return NULL;
}
@@ -2178,6 +2219,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf( str, sizeof(str),
"Error in fseek() reading object from .shp file at offset %u",
psSHP->panRecOffset[hEntity]);
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
return NULL;
@@ -2205,6 +2247,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf( str, sizeof(str),
"Sanity check failed when trying to recover from inconsistent .shx/.shp with shape %d",
hEntity );
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
return NULL;
@@ -2220,6 +2263,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf( str, sizeof(str),
"Error in fread() reading object of size %d at offset %u from .shp file",
nEntitySize, psSHP->panRecOffset[hEntity] );
+ str[sizeof(str)-1] = '\0';
psSHP->sHooks.Error( str );
return NULL;
@@ -2230,6 +2274,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : nEntitySize = %d",
hEntity, nEntitySize);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
return NULL;
}
@@ -2279,6 +2324,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : nEntitySize = %d",
hEntity, nEntitySize);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2313,6 +2359,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d, nPoints=%u, nParts=%u.",
hEntity, nPoints, nParts);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2337,6 +2384,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d, nPoints=%u, nParts=%u, nEntitySize=%d.",
hEntity, nPoints, nParts, nEntitySize);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2369,6 +2417,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Not enough memory to allocate requested memory (nPoints=%u, nParts=%u) for shape %d. "
"Probably broken SHP file", nPoints, nParts, hEntity );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2394,6 +2443,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
hEntity, i, psShape->panPartStart[i], psShape->nVertices);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2403,6 +2453,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
hEntity, i, psShape->panPartStart[i], i - 1, psShape->panPartStart[i - 1]);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2516,6 +2567,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : nEntitySize = %d",
hEntity, nEntitySize);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2530,6 +2582,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : nPoints = %u",
hEntity, nPoints);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2545,6 +2598,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : nPoints = %u, nEntitySize = %d",
hEntity, nPoints, nEntitySize);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2572,6 +2626,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Not enough memory to allocate requested memory (nPoints=%u) for shape %d. "
"Probably broken SHP file", nPoints, hEntity );
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
@@ -2682,6 +2737,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
snprintf(szErrorMsg, sizeof(szErrorMsg),
"Corrupted .shp file : shape %d : nEntitySize = %d",
hEntity, nEntitySize);
+ szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
psSHP->sHooks.Error( szErrorMsg );
SHPDestroyObject(psShape);
return NULL;
diff --git a/web/release.html b/web/release.html
index ea0f3d6..ad2349d 100644
--- a/web/release.html
+++ b/web/release.html
@@ -12,6 +12,12 @@ the project at www.freshmeat.net. This is currently the only reliable
way of finding out about new releases since there is no shapelib specific
mailing list.<p>
+<b>Release 1.4.1</b>:
+<ul>
+<li> Fix a regression regarding re-writing the last shape
+ of a file (<a href="https://trac.osgeo.org/gdal/ticket/7031">GDAL #7031</a>)
+</ul>
+
<b>Release 1.4.0</b>:
<ul>
<li> Old Makefile build replaced by autoconf/automake (by Sandro Mani)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/shapelib.git
More information about the Pkg-grass-devel
mailing list