You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/08/07 23:21:38 UTC

cvs commit: xml-xerces/c/samples/SEnumVal SEnumVal.cpp

neilg       2003/08/07 14:21:38

  Modified:    c/samples/CreateDOMDocument CreateDOMDocument.cpp
               c/samples/EnumVal EnumVal.cpp
               c/samples/MemParse MemParse.cpp
               c/samples/PParse PParse.cpp
               c/samples/Redirect Redirect.cpp
               c/samples/SAX2Print SAX2Print.cpp
               c/samples/SAXPrint SAXPrint.cpp
               c/samples/SEnumVal SEnumVal.cpp
  Log:
  fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  
  Revision  Changes    Path
  1.17      +6 -2      xml-xerces/c/samples/CreateDOMDocument/CreateDOMDocument.cpp
  
  Index: CreateDOMDocument.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/CreateDOMDocument/CreateDOMDocument.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CreateDOMDocument.cpp	30 May 2003 09:36:34 -0000	1.16
  +++ CreateDOMDocument.cpp	7 Aug 2003 21:21:38 -0000	1.17
  @@ -144,6 +144,7 @@
       }
   
       // Watch for special case help request
  +    int errorCode = 0;
       if (argC > 1)
       {
           XERCES_STD_QUALIFIER cout << "\nUsage:\n"
  @@ -151,8 +152,11 @@
                   "This program creates a new DOM document from scratch in memory.\n"
                   "It then prints the count of elements in the tree.\n"
                <<  XERCES_STD_QUALIFIER endl;
  +        errorCode = 1;
  +    }
  +    if(errorCode) {
           XMLPlatformUtils::Terminate();
  -        return 1;
  +        return errorCode;
       }
   
       {
  
  
  
  1.21      +8 -2      xml-xerces/c/samples/EnumVal/EnumVal.cpp
  
  Index: EnumVal.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/EnumVal/EnumVal.cpp,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- EnumVal.cpp	30 May 2003 09:36:35 -0000	1.20
  +++ EnumVal.cpp	7 Aug 2003 21:21:38 -0000	1.21
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.21  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.20  2003/05/30 09:36:35  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -225,7 +228,6 @@
       {
            XERCES_STD_QUALIFIER cerr   << "Error during initialization! Message:\n"
                   << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
  -         XMLPlatformUtils::Terminate();
            return 1;
       }
   
  @@ -263,6 +265,7 @@
       //  Get the starting time and kick off the parse of the indicated
       //  file. Catch any exceptions that might propogate out of it.
       //
  +    int errorCode = 0;
       try
       {
           parser->parse(xmlFile);
  @@ -274,8 +277,11 @@
           XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
                << "Exception message is:  \n"
                << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
  +        errorCode = 4;
  +    }
  +    if(errorCode) {
           XMLPlatformUtils::Terminate();
  -        return 4;
  +        return errorCode;
       }
   
       if (!errorCount) {
  
  
  
  1.15      +9 -1      xml-xerces/c/samples/MemParse/MemParse.cpp
  
  Index: MemParse.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/MemParse/MemParse.cpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MemParse.cpp	30 May 2003 09:36:35 -0000	1.14
  +++ MemParse.cpp	7 Aug 2003 21:21:38 -0000	1.15
  @@ -57,6 +57,9 @@
   
   /*
    * $Log$
  + * Revision 1.15  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.14  2003/05/30 09:36:35  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -317,6 +320,7 @@
       //
       unsigned long duration;
       int errorCount = 0;
  +    int errorCode = 0;
       try
       {
           const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  @@ -331,7 +335,11 @@
           XERCES_STD_QUALIFIER cerr << "\nError during parsing memory stream:\n"
                << "Exception message is:  \n"
                << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
  -        return 4;
  +        errorCode = 4;
  +    }
  +    if(errorCode) {
  +        XMLPlatformUtils::Terminate();
  +        return errorCode;
       }
   
       // Print out the stats that we collected and time taken.
  
  
  
  1.16      +9 -2      xml-xerces/c/samples/PParse/PParse.cpp
  
  Index: PParse.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/PParse/PParse.cpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- PParse.cpp	30 May 2003 09:36:35 -0000	1.15
  +++ PParse.cpp	7 Aug 2003 21:21:38 -0000	1.16
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.16  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.15  2003/05/30 09:36:35  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -310,6 +313,7 @@
       //  for. When it does, we fall out then.
       //
       unsigned long duration;
  +    int errorCode = 0;
       try
       {
           // Create a progressive scan token
  @@ -351,10 +355,13 @@
                << "Exception message is: \n"
                << StrX(toCatch.getMessage())
                << "\n" << XERCES_STD_QUALIFIER endl;
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  +        errorCode = 4;
       }
   
  +    if(errorCode) {
  +        XMLPlatformUtils::Terminate();
  +        return errorCode;
  +    }
   
       if (!errorCount) {
           XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
  
  
  
  1.9       +9 -1      xml-xerces/c/samples/Redirect/Redirect.cpp
  
  Index: Redirect.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/Redirect/Redirect.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Redirect.cpp	30 May 2003 09:36:35 -0000	1.8
  +++ Redirect.cpp	7 Aug 2003 21:21:38 -0000	1.9
  @@ -75,6 +75,9 @@
    * to read the contents of 'personal.dtd'.
    *
    * $Log$
  + * Revision 1.9  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.8  2003/05/30 09:36:35  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -178,6 +181,7 @@
       //
       unsigned long duration;
       int errorCount = 0;
  +    int errorCode = 0;
       try
       {
           const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  @@ -192,8 +196,12 @@
           XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
                   << "Exception message is:  \n"
                   << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
  +        errorCode = 4;
  +    }
  +
  +    if(errorCode) {
           XMLPlatformUtils::Terminate();
  -        return 4;
  +        return errorCode;
       }
   
       // Print out the stats that we collected and time taken.
  
  
  
  1.14      +9 -1      xml-xerces/c/samples/SAX2Print/SAX2Print.cpp
  
  Index: SAX2Print.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Print/SAX2Print.cpp,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SAX2Print.cpp	30 May 2003 09:36:36 -0000	1.13
  +++ SAX2Print.cpp	7 Aug 2003 21:21:38 -0000	1.14
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.14  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.13  2003/05/30 09:36:36  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -335,6 +338,7 @@
       //
   
       int errorCount = 0;
  +    int errorCode = 0;
       try
       {
           SAX2PrintHandlers handler(encodingName, unRepFlags, expandNamespaces);
  @@ -349,8 +353,12 @@
           XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n  Error: "
                << StrX(toCatch.getMessage())
                << "\n" << XERCES_STD_QUALIFIER endl;
  +        errorCode = 4;
  +    }
  +
  +    if(errorCode) {
           XMLPlatformUtils::Terminate();
  -        return 4;
  +        return errorCode;
       }
   
       //
  
  
  
  1.22      +8 -1      xml-xerces/c/samples/SAXPrint/SAXPrint.cpp
  
  Index: SAXPrint.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAXPrint/SAXPrint.cpp,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SAXPrint.cpp	30 May 2003 09:36:36 -0000	1.21
  +++ SAXPrint.cpp	7 Aug 2003 21:21:38 -0000	1.22
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.22  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.21  2003/05/30 09:36:36  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -339,6 +342,7 @@
       //  handler for the parser-> Then parse the file and catch any exceptions
       //  that propogate out
       //
  +    int errorCode = 0;
       try
       {
           SAXPrintHandlers handler(encodingName, unRepFlags);
  @@ -353,8 +357,11 @@
           XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n  Error: "
                << StrX(toCatch.getMessage())
                << "\n" << XERCES_STD_QUALIFIER endl;
  +        errorCode = -1;
  +    }
  +    if(errorCode) {
           XMLPlatformUtils::Terminate();
  -        return -1;
  +        return errorCode;
       }
   
       //
  
  
  
  1.17      +14 -6     xml-xerces/c/samples/SEnumVal/SEnumVal.cpp
  
  Index: SEnumVal.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SEnumVal/SEnumVal.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SEnumVal.cpp	30 May 2003 09:36:36 -0000	1.16
  +++ SEnumVal.cpp	7 Aug 2003 21:21:38 -0000	1.17
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.17  2003/08/07 21:21:38  neilg
  + * fix segmentation faults that may arise when the parser throws exceptions during document parsing.  In general, XMLPlatformUtils::Terminate() should not be called from within a catch statement.
  + *
    * Revision 1.16  2003/05/30 09:36:36  gareth
    * Use new macros for iostream.h and std:: issues.
    *
  @@ -200,6 +203,9 @@
   // ---------------------------------------------------------------------------
   int main(int argC, char* argV[])
   {
  +    // cannot return out of catch-blocks lest exception-destruction
  +    // result in calls to destroyed memory handler!
  +    int errorCode = 0;
       // Initialize the XML4C system
       try
       {
  @@ -210,9 +216,12 @@
       {
            XERCES_STD_QUALIFIER cerr   << "Error during initialization! Message:\n"
                   << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
  -         XMLPlatformUtils::Terminate();
  -         return 1;
  +         errorCode = 1;
       }
  +    if(errorCode) {
  +        XMLPlatformUtils::Terminate();
  +        return errorCode;
  +    } 
   
       // Check command line and extract arguments.
       // We only have one required parameter, which is the file to process
  @@ -233,13 +242,12 @@
           XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << argV[1] << "'\n"
                << "Exception message is:  \n"
                << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
  -        XMLPlatformUtils::Terminate();
  -        return 3;
  +        errorCode = 3;
       }
   
       XMLPlatformUtils::Terminate();
   
  -	return 0;
  +	return errorCode;
   }
   
   void process(char* const xmlFile)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org