1886 {
1889
1891 {
1892 snprintf(szErrorMsg, sizeof(szErrorMsg),
1893 "Corrupted .shp file : shape %d : nEntitySize = %d",
1895 psSHP->sHooks.Error( szErrorMsg );
1897 return NULL;
1898 }
1899 memcpy( &nPoints, psSHP->pabyRec + 44, 4 );
1900
1902
1903 if (nPoints > 50 * 1000 * 1000)
1904 {
1905 snprintf(szErrorMsg, sizeof(szErrorMsg),
1906 "Corrupted .shp file : shape %d : nPoints = %d",
1907 hEntity, nPoints);
1908 psSHP->sHooks.Error( szErrorMsg );
1910 return NULL;
1911 }
1912
1913 nRequiredSize = 48 + nPoints * 16;
1915 {
1916 nRequiredSize += 16 + nPoints * 8;
1917 }
1919 {
1920 snprintf(szErrorMsg, sizeof(szErrorMsg),
1921 "Corrupted .shp file : shape %d : nPoints = %d, nEntitySize = %d",
1923 psSHP->sHooks.Error( szErrorMsg );
1925 return NULL;
1926 }
1927
1929 psShape->padfX = (
double *) calloc(nPoints,
sizeof(
double));
1930 psShape->padfY = (
double *) calloc(nPoints,
sizeof(
double));
1931 psShape->padfZ = (
double *) calloc(nPoints,
sizeof(
double));
1932 psShape->padfM = (
double *) calloc(nPoints,
sizeof(
double));
1933
1938 {
1939 snprintf(szErrorMsg, sizeof(szErrorMsg),
1940 "Not enough memory to allocate requested memory (nPoints=%d) for shape %d. "
1941 "Probably broken SHP file", hEntity, nPoints );
1942 psSHP->sHooks.Error( szErrorMsg );
1944 return NULL;
1945 }
1946
1947 for( i = 0; i < nPoints; i++ )
1948 {
1949 memcpy(
psShape->padfX+i, psSHP->pabyRec + 48 + 16 * i, 8 );
1950 memcpy(
psShape->padfY+i, psSHP->pabyRec + 48 + 16 * i + 8, 8 );
1951
1954 }
1955
1956 nOffset = 48 + 16*nPoints;
1957
1958
1959
1960
1961 memcpy( &(
psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8 );
1962 memcpy( &(
psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
1963 memcpy( &(
psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
1964 memcpy( &(
psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
1965
1970
1971
1972
1973
1975 {
1976 memcpy( &(
psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
1977 memcpy( &(
psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
1978
1981
1982 for( i = 0; i < nPoints; i++ )
1983 {
1985 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
1987 }
1988
1989 nOffset += 16 + 8*nPoints;
1990 }
1991
1992
1993
1994
1995
1996
1997
1999 {
2000 memcpy( &(
psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
2001 memcpy( &(
psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
2002
2005
2006 for( i = 0; i < nPoints; i++ )
2007 {
2009 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
2011 }
2013 }
2014 }
static void SwapWord(int length, void *wordP)
void SHPAPI_CALL SHPDestroyObject(SHPObject *psShape)