shapelib: Add new package.
This commit is contained in:
47
mingw-w64-shapelib/PKGBUILD
Normal file
47
mingw-w64-shapelib/PKGBUILD
Normal file
@@ -0,0 +1,47 @@
|
||||
# Maintainer: Alexey Pavlov <alexpux@gmail.com>
|
||||
|
||||
_realname=shapelib
|
||||
_mingw_suff=mingw-w64-${CARCH}
|
||||
pkgname="${_mingw_suff}-${_realname}"
|
||||
pkgver=1.3.0
|
||||
pkgrel=1
|
||||
pkgdesc="simple C API for reading and writing ESRI Shapefiles (mingw-w64)"
|
||||
arch=('any')
|
||||
url="http://shapelib.maptools.org/"
|
||||
license=("LGPL" "MIT")
|
||||
makedepends=("${_mingw_suff}-gcc" "${_mingw_suff}-pkg-config")
|
||||
depends=("${_mingw_suff}-gcc-libs" "${_mingw_suff}-proj")
|
||||
options=(strip staticlibs)
|
||||
source=("http://download.osgeo.org/shapelib/${_realname}-${pkgver}.tar.gz"
|
||||
shapelib_autotools.patch
|
||||
shapelib_backports.patch)
|
||||
sha1sums=('599fde6f69424fa55da281506b297f3976585b85'
|
||||
'a0eb9196591e5f5841b2de09e29bf04a40cd475d'
|
||||
'4ae20269dd1c62679fd132baf7c1cc194af89f7f')
|
||||
|
||||
prepare() {
|
||||
cd ${srcdir}/${_realname}-${pkgver}
|
||||
patch -p1 -i ${srcdir}/shapelib_autotools.patch
|
||||
patch -p1 -i ${srcdir}/shapelib_backports.patch
|
||||
|
||||
NOCONFIGURE=1 sh ./autogen.sh
|
||||
}
|
||||
|
||||
build() {
|
||||
#export lt_cv_deplibs_check_method='pass_all'
|
||||
mkdir -p "${srcdir}/build-${MINGW_CHOST}"
|
||||
cd "${srcdir}/build-${MINGW_CHOST}"
|
||||
"${srcdir}"/${_realname}-${pkgver}/configure \
|
||||
--prefix=${MINGW_PREFIX} \
|
||||
--build=${MINGW_CHOST} \
|
||||
--host=${MINGW_CHOST} \
|
||||
--enable-shared \
|
||||
--enable-static
|
||||
make
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "${srcdir}/build-${MINGW_CHOST}"
|
||||
make DESTDIR="$pkgdir" install
|
||||
find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
|
||||
}
|
||||
6396
mingw-w64-shapelib/shapelib_autotools.patch
Normal file
6396
mingw-w64-shapelib/shapelib_autotools.patch
Normal file
File diff suppressed because it is too large
Load Diff
177
mingw-w64-shapelib/shapelib_backports.patch
Normal file
177
mingw-w64-shapelib/shapelib_backports.patch
Normal file
@@ -0,0 +1,177 @@
|
||||
diff --git a/dbfopen.c b/dbfopen.c
|
||||
index fbe7b06..69d8098 100644
|
||||
--- a/dbfopen.c
|
||||
+++ b/dbfopen.c
|
||||
@@ -687,15 +687,22 @@ DBFCreateLL( const char * pszFilename, const char * pszCodePage, SAHooks *psHook
|
||||
/* -------------------------------------------------------------------- */
|
||||
fp = psHooks->FOpen( pszFullname, "wb" );
|
||||
if( fp == NULL )
|
||||
+ {
|
||||
+ free( pszBasename );
|
||||
+ free( pszFullname );
|
||||
return( NULL );
|
||||
+ }
|
||||
|
||||
psHooks->FWrite( &chZero, 1, 1, fp );
|
||||
psHooks->FClose( fp );
|
||||
|
||||
fp = psHooks->FOpen( pszFullname, "rb+" );
|
||||
if( fp == NULL )
|
||||
+ {
|
||||
+ free( pszBasename );
|
||||
+ free( pszFullname );
|
||||
return( NULL );
|
||||
-
|
||||
+ }
|
||||
|
||||
sprintf( pszFullname, "%s.cpg", pszBasename );
|
||||
if( pszCodePage != NULL )
|
||||
diff --git a/shptree.c b/shptree.c
|
||||
index 409134e..00673aa 100644
|
||||
--- a/shptree.c
|
||||
+++ b/shptree.c
|
||||
@@ -844,22 +844,23 @@ void SHPCloseDiskTree( SHPTreeDiskHandle hDiskTree )
|
||||
static int
|
||||
SHPSearchDiskTreeNode( SHPTreeDiskHandle hDiskTree, double *padfBoundsMin, double *padfBoundsMax,
|
||||
int **ppanResultBuffer, int *pnBufferMax,
|
||||
- int *pnResultCount, int bNeedSwap )
|
||||
+ int *pnResultCount, int bNeedSwap, int nRecLevel )
|
||||
|
||||
{
|
||||
- int i;
|
||||
- int offset;
|
||||
- int numshapes, numsubnodes;
|
||||
+ unsigned int i;
|
||||
+ unsigned int offset;
|
||||
+ unsigned int numshapes, numsubnodes;
|
||||
double adfNodeBoundsMin[2], adfNodeBoundsMax[2];
|
||||
+ int nFReadAcc;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Read and unswap first part of node info. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
- hDiskTree->sHooks.FRead( &offset, 4, 1, hDiskTree->fpQIX );
|
||||
+ nFReadAcc = (int)hDiskTree->sHooks.FRead( &offset, 4, 1, hDiskTree->fpQIX );
|
||||
if ( bNeedSwap ) SwapWord ( 4, &offset );
|
||||
|
||||
- hDiskTree->sHooks.FRead( adfNodeBoundsMin, sizeof(double), 2, hDiskTree->fpQIX );
|
||||
- hDiskTree->sHooks.FRead( adfNodeBoundsMax, sizeof(double), 2, hDiskTree->fpQIX );
|
||||
+ nFReadAcc += (int)hDiskTree->sHooks.FRead( adfNodeBoundsMin, sizeof(double), 2, hDiskTree->fpQIX );
|
||||
+ nFReadAcc += (int)hDiskTree->sHooks.FRead( adfNodeBoundsMax, sizeof(double), 2, hDiskTree->fpQIX );
|
||||
if ( bNeedSwap )
|
||||
{
|
||||
SwapWord( 8, adfNodeBoundsMin + 0 );
|
||||
@@ -868,9 +869,30 @@ SHPSearchDiskTreeNode( SHPTreeDiskHandle hDiskTree, double *padfBoundsMin, doubl
|
||||
SwapWord( 8, adfNodeBoundsMax + 1 );
|
||||
}
|
||||
|
||||
- hDiskTree->sHooks.FRead( &numshapes, 4, 1, hDiskTree->fpQIX );
|
||||
+ nFReadAcc += (int)hDiskTree->sHooks.FRead( &numshapes, 4, 1, hDiskTree->fpQIX );
|
||||
if ( bNeedSwap ) SwapWord ( 4, &numshapes );
|
||||
|
||||
+ /* Check that we could read all previous values */
|
||||
+ if( nFReadAcc != 1 + 2 + 2 + 1 )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("I/O error");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
+ /* Sanity checks to avoid int overflows in later computation */
|
||||
+ if( offset > INT_MAX - sizeof(int) )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("Invalid value for offset");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
+ if( numshapes > (INT_MAX - offset - sizeof(int)) / sizeof(int) ||
|
||||
+ numshapes > INT_MAX / sizeof(int) - *pnResultCount )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("Invalid value for numshapes");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* If we don't overlap this node at all, we can just fseek() */
|
||||
/* pass this node info and all subnodes. */
|
||||
@@ -890,13 +912,31 @@ SHPSearchDiskTreeNode( SHPTreeDiskHandle hDiskTree, double *padfBoundsMin, doubl
|
||||
{
|
||||
if( *pnResultCount + numshapes > *pnBufferMax )
|
||||
{
|
||||
- *pnBufferMax = (int) ((*pnResultCount + numshapes + 100) * 1.25);
|
||||
- *ppanResultBuffer = (int *)
|
||||
+ int* pNewBuffer;
|
||||
+
|
||||
+ *pnBufferMax = (*pnResultCount + numshapes + 100) * 5 / 4;
|
||||
+
|
||||
+ if( *pnBufferMax > INT_MAX / sizeof(int) )
|
||||
+ *pnBufferMax = *pnResultCount + numshapes;
|
||||
+
|
||||
+ pNewBuffer = (int *)
|
||||
SfRealloc( *ppanResultBuffer, *pnBufferMax * sizeof(int) );
|
||||
+
|
||||
+ if( pNewBuffer == NULL )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("Out of memory error");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
+ *ppanResultBuffer = pNewBuffer;
|
||||
}
|
||||
|
||||
- hDiskTree->sHooks.FRead( *ppanResultBuffer + *pnResultCount,
|
||||
- sizeof(int), numshapes, hDiskTree->fpQIX );
|
||||
+ if( hDiskTree->sHooks.FRead( *ppanResultBuffer + *pnResultCount,
|
||||
+ sizeof(int), numshapes, hDiskTree->fpQIX ) != numshapes )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("I/O error");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
|
||||
if (bNeedSwap )
|
||||
{
|
||||
@@ -910,14 +950,23 @@ SHPSearchDiskTreeNode( SHPTreeDiskHandle hDiskTree, double *padfBoundsMin, doubl
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Process the subnodes. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
- hDiskTree->sHooks.FRead( &numsubnodes, 4, 1, hDiskTree->fpQIX );
|
||||
+ if( hDiskTree->sHooks.FRead( &numsubnodes, 4, 1, hDiskTree->fpQIX ) != 1 )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("I/O error");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
if ( bNeedSwap ) SwapWord ( 4, &numsubnodes );
|
||||
+ if( numsubnodes > 0 && nRecLevel == 32 )
|
||||
+ {
|
||||
+ hDiskTree->sHooks.Error("Shape tree is too deep");
|
||||
+ return FALSE;
|
||||
+ }
|
||||
|
||||
for(i=0; i<numsubnodes; i++)
|
||||
{
|
||||
if( !SHPSearchDiskTreeNode( hDiskTree, padfBoundsMin, padfBoundsMax,
|
||||
ppanResultBuffer, pnBufferMax,
|
||||
- pnResultCount, bNeedSwap ) )
|
||||
+ pnResultCount, bNeedSwap, nRecLevel + 1 ) )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -1014,7 +1063,7 @@ int* SHPSearchDiskTreeEx( SHPTreeDiskHandle hDiskTree,
|
||||
/* -------------------------------------------------------------------- */
|
||||
if( !SHPSearchDiskTreeNode( hDiskTree, padfBoundsMin, padfBoundsMax,
|
||||
&panResultBuffer, &nBufferMax,
|
||||
- pnShapeCount, bNeedSwap ) )
|
||||
+ pnShapeCount, bNeedSwap, 0 ) )
|
||||
{
|
||||
if( panResultBuffer != NULL )
|
||||
free( panResultBuffer );
|
||||
@@ -1025,6 +1074,10 @@ int* SHPSearchDiskTreeEx( SHPTreeDiskHandle hDiskTree,
|
||||
/* Sort the id array */
|
||||
/* -------------------------------------------------------------------- */
|
||||
qsort(panResultBuffer, *pnShapeCount, sizeof(int), compare_ints);
|
||||
+
|
||||
+ /* To distinguish between empty intersection from error case */
|
||||
+ if( panResultBuffer == NULL )
|
||||
+ panResultBuffer = (int*) calloc(1, sizeof(int));
|
||||
|
||||
return panResultBuffer;
|
||||
}
|
||||
Reference in New Issue
Block a user