PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ if() [5/10]

if ( nEntitySize  ,
psSHP->  nBufSize 
)

Definition at line 1909 of file shpopen.c.

1910 {
1911 uchar* pabyRecNew;
1912 int nNewBufSize = nEntitySize;
1913 if( nNewBufSize < INT_MAX - nNewBufSize / 3 )
1914 nNewBufSize += nNewBufSize / 3;
1915 else
1916 nNewBufSize = INT_MAX;
1917
1918 /* Before allocating too much memory, check that the file is big enough */
1919 /* and do not trust the file size in the header the first time we */
1920 /* need to allocate more than 10 MB */
1921 if( nNewBufSize >= 10 * 1024 * 1024 )
1922 {
1923 if( psSHP->nBufSize < 10 * 1024 * 1024 )
1924 {
1925 SAOffset nFileSize;
1926 psSHP->sHooks.FSeek( psSHP->fpSHP, 0, 2 );
1927 nFileSize = psSHP->sHooks.FTell(psSHP->fpSHP);
1928 if( nFileSize >= UINT_MAX )
1929 psSHP->nFileSize = UINT_MAX;
1930 else
1931 psSHP->nFileSize = STATIC_CAST(unsigned int, nFileSize);
1932 }
1933
1934 if( psSHP->panRecOffset[hEntity] >= psSHP->nFileSize ||
1935 /* We should normally use nEntitySize instead of*/
1936 /* psSHP->panRecSize[hEntity] in the below test, but because of */
1937 /* the case of non conformant .shx files detailed a bit below, */
1938 /* let be more tolerant */
1939 psSHP->panRecSize[hEntity] > psSHP->nFileSize - psSHP->panRecOffset[hEntity] )
1940 {
1941 char str[128];
1942 snprintf( str, sizeof(str),
1943 "Error in fread() reading object of size %d at offset %u from .shp file",
1944 nEntitySize, psSHP->panRecOffset[hEntity] );
1945 str[sizeof(str)-1] = '\0';
1946
1947 psSHP->sHooks.Error( str );
1948 return SHPLIB_NULLPTR;
1949 }
1950 }
1951
1952 pabyRecNew = STATIC_CAST(uchar *, SfRealloc(psSHP->pabyRec,nNewBufSize));
1953 if (pabyRecNew == SHPLIB_NULLPTR)
1954 {
1955 snprintf( szErrorMsg, sizeof(szErrorMsg),
1956 "Not enough memory to allocate requested memory (nNewBufSize=%d). "
1957 "Probably broken SHP file", nNewBufSize);
1958 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1959 psSHP->sHooks.Error( szErrorMsg );
1960 return SHPLIB_NULLPTR;
1961 }
1962
1963 /* Only set new buffer size after successful alloc */
1964 psSHP->pabyRec = pabyRecNew;
1965 psSHP->nBufSize = nNewBufSize;
1966 }
#define str(s)
unsigned long SAOffset
Definition shapefil.h:286
static void * SfRealloc(void *pMem, int nNewSize)
Definition shpopen.c:131
nEntitySize
Definition shpopen.c:1908
unsigned char uchar
Definition shpopen.c:49
#define STATIC_CAST(type, x)
Definition shpopen.c:100
#define SHPLIB_NULLPTR
Definition shpopen.c:101

References nEntitySize, SfRealloc(), SHPLIB_NULLPTR, STATIC_CAST, and str.

Here is the call graph for this function: