PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ if() [5/10]

if ( nEntitySize  ,
psSHP->  nBufSize 
)

Definition at line 1900 of file shpopen.c.

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

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

Here is the call graph for this function: