LCOV - code coverage report
Current view: directory - ogr - ogr_expat.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 16 8 50.0 %
Date: 2010-01-09 Functions: 3 2 66.7 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_expat.cpp 18063 2009-11-21 21:11:49Z warmerdam $
       3                 :  *
       4                 :  * Project:  OGR
       5                 :  * Purpose:  Convenience function for parsing with Expat library
       6                 :  * Author:   Even Rouault, even dot rouault at mines dash paris dot org
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2009, Even Rouault
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #ifdef HAVE_EXPAT
      31                 : 
      32                 : #include "ogr_expat.h"
      33                 : #include "cpl_error.h"
      34                 : 
      35                 : CPL_CVSID("$Id: ogr_expat.cpp 18063 2009-11-21 21:11:49Z warmerdam $");
      36                 : 
      37                 : #define OGR_EXPAT_MAX_ALLOWED_ALLOC 10000000
      38                 : 
      39            6171 : static void* OGRExpatMalloc(size_t size)
      40                 : {
      41            6171 :     if (size < OGR_EXPAT_MAX_ALLOWED_ALLOC)
      42            6171 :         return malloc(size);
      43                 :     else
      44                 :     {
      45                 :         CPLError(CE_Failure, CPLE_OutOfMemory,
      46               0 :                  "Expat tried to malloc %d bytes. File probably corrupted", (int)size);
      47               0 :         return NULL;
      48                 :     }
      49                 : }
      50                 : 
      51               0 : static void* OGRExpatRealloc(void *ptr, size_t size)
      52                 : {
      53               0 :     if (size < OGR_EXPAT_MAX_ALLOWED_ALLOC)
      54               0 :         return realloc(ptr, size);
      55                 :     else
      56                 :     {
      57                 :         CPLError(CE_Failure, CPLE_OutOfMemory,
      58               0 :                  "Expat tried to realloc %d bytes. File probably corrupted", (int)size);
      59               0 :         free(ptr);
      60               0 :         return NULL;
      61                 :     }
      62                 : }
      63                 : 
      64             237 : XML_Parser OGRCreateExpatXMLParser()
      65                 : {
      66                 :     XML_Memory_Handling_Suite memsuite;
      67             237 :     memsuite.malloc_fcn = OGRExpatMalloc;
      68             237 :     memsuite.realloc_fcn = OGRExpatRealloc;
      69             237 :     memsuite.free_fcn = free;
      70             237 :     return XML_ParserCreate_MM(NULL, &memsuite, NULL);
      71                 : }
      72                 : 
      73                 : #endif

Generated by: LCOV version 1.7