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

◆ if() [5/10]

if ( nEntitySize  ,
psSHP->  nBufSize 
)

Definition at line 1898 of file shpopen.c.

1899 {
1900 uchar* pabyRecNew;
1901 int nNewBufSize = nEntitySize;
1902 if( nNewBufSize < INT_MAX - nNewBufSize / 3 )
1903 nNewBufSize += nNewBufSize / 3;
1904 else
1905 nNewBufSize = INT_MAX;
1906
1907 /* Before allocating too much memory, check that the file is big enough */
1908 /* and do not trust the file size in the header the first time we */
1909 /* need to allocate more than 10 MB */
1910 if( nNewBufSize >= 10 * 1024 * 1024 )
1911 {
1912 if( psSHP->nBufSize < 10 * 1024 * 1024 )
1913 {
1914 SAOffset nFileSize;
1915 psSHP->sHooks.FSeek( psSHP->fpSHP, 0, 2 );
1916 nFileSize = psSHP->sHooks.FTell(psSHP->fpSHP);
1917 if( nFileSize >= UINT_MAX )
1918 psSHP->nFileSize = UINT_MAX;
1919 else
1920 psSHP->nFileSize = STATIC_CAST(unsigned int, nFileSize);
1921 }
1922
1923 if( psSHP->panRecOffset[hEntity] >= psSHP->nFileSize ||
1924 /* We should normally use nEntitySize instead of*/
1925 /* psSHP->panRecSize[hEntity] in the below test, but because of */
1926 /* the case of non conformant .shx files detailed a bit below, */
1927 /* let be more tolerant */
1928 psSHP->panRecSize[hEntity] > psSHP->nFileSize - psSHP->panRecOffset[hEntity] )
1929 {
1930 char str[128];
1931 snprintf( str, sizeof(str),
1932 "Error in fread() reading object of size %d at offset %u from .shp file",
1933 nEntitySize, psSHP->panRecOffset[hEntity] );
1934 str[sizeof(str)-1] = '\0';
1935
1936 psSHP->sHooks.Error( str );
1937 return SHPLIB_NULLPTR;
1938 }
1939 }
1940
1941 pabyRecNew = STATIC_CAST(uchar *, SfRealloc(psSHP->pabyRec,nNewBufSize));
1942 if (pabyRecNew == SHPLIB_NULLPTR)
1943 {
1944 snprintf( szErrorMsg, sizeof(szErrorMsg),
1945 "Not enough memory to allocate requested memory (nNewBufSize=%d). "
1946 "Probably broken SHP file", nNewBufSize);
1947 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1948 psSHP->sHooks.Error( szErrorMsg );
1949 return SHPLIB_NULLPTR;
1950 }
1951
1952 /* Only set new buffer size after successful alloc */
1953 psSHP->pabyRec = pabyRecNew;
1954 psSHP->nBufSize = nNewBufSize;
1955 }
#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:1897
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: