From ce56d8f8a8c9272791d14e73dd846fbeaa4d47b4 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 24 May 2021 20:59:30 +0200
Subject: gcc2 build fix


diff --git a/lib/xmlparse.c b/lib/xmlparse.c
index 7db28d0..0f7f139 100644
--- a/lib/xmlparse.c
+++ b/lib/xmlparse.c
@@ -718,7 +718,8 @@ XML_ParserCreate(const XML_Char *encodingName) {
 
 XML_Parser XMLCALL
 XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) {
-  XML_Char tmp[2] = {nsSep, 0};
+  XML_Char tmp[2] = {0, 0};
+  tmp[0] = nsSep;
   return XML_ParserCreate_MM(encodingName, NULL, tmp);
 }
 
@@ -1343,7 +1344,8 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context,
      would be otherwise.
   */
   if (parser->m_ns) {
-    XML_Char tmp[2] = {parser->m_namespaceSeparator, 0};
+    XML_Char tmp[2] = {0, 0};
+    tmp[0] = parser->m_namespaceSeparator;
     parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd);
   } else {
     parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd);
@@ -3464,7 +3466,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
     if (parser->m_nsAttsPower >= sizeof(unsigned int) * 8 /* bits per byte */) {
       return XML_ERROR_NO_MEMORY;
     }
-
+{
     unsigned int nsAttsSize = 1u << parser->m_nsAttsPower;
     unsigned char oldNsAttsPower = parser->m_nsAttsPower;
     /* size of hash table must be at least 2 * (# of prefixed attributes) */
@@ -3621,6 +3623,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
       } else                     /* not prefixed */
         ((XML_Char *)s)[-1] = 0; /* clear flag */
     }
+    }
   }
   /* clear flags for the remaining attributes */
   for (; i < attIndex; i += 2)
@@ -3800,13 +3803,14 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
         return XML_ERROR_NO_MEMORY;
       }
 #endif
-
+{
       XML_Char *temp = (XML_Char *)REALLOC(
           parser, b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE));
       if (temp == NULL)
         return XML_ERROR_NO_MEMORY;
       b->uri = temp;
       b->uriAlloc = len + EXPAND_SPARE;
+}
     }
     parser->m_freeBindingList = b->nextTagBinding;
   } else {
@@ -5158,7 +5162,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
             if (parser->m_groupSize > (unsigned int)(-1) / 2u) {
               return XML_ERROR_NO_MEMORY;
             }
-
+{
             char *const new_connector = (char *)REALLOC(
                 parser, parser->m_groupConnector, parser->m_groupSize *= 2);
             if (new_connector == NULL) {
@@ -5166,6 +5170,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
               return XML_ERROR_NO_MEMORY;
             }
             parser->m_groupConnector = new_connector;
+}
           }
 
           if (dtd->scaffIndex) {
@@ -5178,12 +5183,13 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
               return XML_ERROR_NO_MEMORY;
             }
 #endif
-
+{
             int *const new_scaff_index = (int *)REALLOC(
                 parser, dtd->scaffIndex, parser->m_groupSize * sizeof(int));
             if (new_scaff_index == NULL)
               return XML_ERROR_NO_MEMORY;
             dtd->scaffIndex = new_scaff_index;
+}
           }
         } else {
           parser->m_groupConnector
@@ -6260,7 +6266,7 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
       if (type->allocDefaultAtts > INT_MAX / 2) {
         return 0;
       }
-
+{
       int count = type->allocDefaultAtts * 2;
 
       /* Detect and prevent integer overflow.
@@ -6279,7 +6285,8 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
         return 0;
       type->allocDefaultAtts = count;
       type->defaultAtts = temp;
-    }
+}
+   }
   }
   att = type->defaultAtts + type->nDefaultAtts;
   att->id = attId;
@@ -6928,7 +6935,7 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) {
       if (newPower >= sizeof(unsigned long) * 8 /* bits per byte */) {
         return NULL;
       }
-
+{
       size_t newSize = (size_t)1 << newPower;
       unsigned long newMask = (unsigned long)newSize - 1;
 
@@ -6937,6 +6944,7 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) {
         return NULL;
       }
 
+{
       size_t tsize = newSize * sizeof(NAMED *);
       NAMED **newV = table->mem->malloc_fcn(tsize);
       if (! newV)
@@ -6966,6 +6974,8 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) {
         i < step ? (i += newSize - step) : (i -= step);
       }
     }
+}
+    }
   }
   table->v[i] = table->mem->malloc_fcn(createSize);
   if (! table->v[i])
@@ -7357,11 +7367,12 @@ build_model(XML_Parser parser) {
       > (size_t)(-1) - dtd->contentStringLen * sizeof(XML_Char)) {
     return NULL;
   }
-
+{
   const size_t allocsize = (dtd->scaffCount * sizeof(XML_Content)
                             + (dtd->contentStringLen * sizeof(XML_Char)));
 
   ret = (XML_Content *)MALLOC(parser, allocsize);
+}
   if (! ret)
     return NULL;
 
@@ -7414,6 +7425,7 @@ build_model(XML_Parser parser) {
    *
    * - The algorithm repeats until all target array indices have been processed.
    */
+{
   XML_Content *dest = ret; /* tree node writing location, moves upwards */
   XML_Content *const destLimit = &ret[dtd->scaffCount];
   XML_Content *jobDest = ret; /* next free writing location in target array */
@@ -7454,7 +7466,7 @@ build_model(XML_Parser parser) {
         (jobDest++)->numchildren = (unsigned int)cn;
     }
   }
-
+}
   return ret;
 }
 
@@ -7526,7 +7538,7 @@ accountingReportStats(XML_Parser originParser, const char *epilog) {
   if (rootParser->m_accounting.debugLevel < 1) {
     return;
   }
-
+{
   const float amplificationFactor
       = accountingGetCurrentAmplification(rootParser);
   fprintf(stderr,
@@ -7536,6 +7548,7 @@ accountingReportStats(XML_Parser originParser, const char *epilog) {
           rootParser->m_accounting.countBytesIndirect,
           (double)amplificationFactor, epilog);
 }
+}
 
 static void
 accountingOnAbort(XML_Parser originParser) {
@@ -7554,6 +7567,7 @@ accountingReportDiff(XML_Parser rootParser,
           bytesMore, (account == XML_ACCOUNT_DIRECT) ? "DIR" : "EXP",
           levelsAwayFromRootParser, source_line, 10, "");
 
+{
   const char ellipis[] = "[..]";
   const size_t ellipsisLength = sizeof(ellipis) /* because compile-time */ - 1;
   const unsigned int contextLength = 10;
@@ -7578,6 +7592,7 @@ accountingReportDiff(XML_Parser rootParser,
   }
   fprintf(stderr, "\"\n");
 }
+}
 
 static XML_Bool
 accountingDiffTolerated(XML_Parser originParser, int tok, const char *before,
@@ -7596,12 +7611,13 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before,
 
   if (account == XML_ACCOUNT_NONE)
     return XML_TRUE; /* because these bytes have been accounted for, already */
-
+{
   unsigned int levelsAwayFromRootParser;
   const XML_Parser rootParser
       = getRootParserOf(originParser, &levelsAwayFromRootParser);
   assert(! rootParser->m_parentParser);
 
+{
   const int isDirect
       = (account == XML_ACCOUNT_DIRECT) && (originParser == rootParser);
   const ptrdiff_t bytesMore = after - before;
@@ -7614,7 +7630,7 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before,
   if (*additionTarget > (XmlBigCount)(-1) - (XmlBigCount)bytesMore)
     return XML_FALSE;
   *additionTarget += bytesMore;
-
+{
   const XmlBigCount countBytesOutput
       = rootParser->m_accounting.countBytesDirect
         + rootParser->m_accounting.countBytesIndirect;
@@ -7633,6 +7649,9 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before,
 
   return tolerated;
 }
+}
+}
+}
 
 unsigned long long
 testingAccountingGetCountBytesDirect(XML_Parser parser) {
@@ -7655,6 +7674,7 @@ entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity,
   if (rootParser->m_entity_stats.debugLevel < 1)
     return;
 
+{
 #  if defined(XML_UNICODE)
   const char *const entityName = "[..]";
 #  else
@@ -7671,6 +7691,7 @@ entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity,
       entity->is_param ? "%" : "&", entityName, action, entity->textLen,
       sourceLine);
 }
+}
 
 static void
 entityTrackingOnOpen(XML_Parser originParser, ENTITY *entity, int sourceLine) {
@@ -8241,9 +8262,11 @@ getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) {
   if (valueOrNull == NULL) {
     return defaultDebugLevel;
   }
+{
   const char *const value = valueOrNull;
 
   errno = 0;
+{
   char *afterValue = (char *)value;
   unsigned long debugLevel = strtoul(value, &afterValue, 10);
   if ((errno != 0) || (afterValue[0] != '\0')) {
@@ -8253,3 +8276,5 @@ getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) {
 
   return debugLevel;
 }
+}
+}
diff --git a/xmlwf/xmlwf.c b/xmlwf/xmlwf.c
index b0cd212..4ccb9a6 100644
--- a/xmlwf/xmlwf.c
+++ b/xmlwf/xmlwf.c
@@ -1050,6 +1050,7 @@ tmain(int argc, XML_Char **argv) {
       XMLWF_SHIFT_ARG_INTO(valueText, argc, argv, i, j);
 
       errno = 0;
+{
       XML_Char *afterValueText = (XML_Char *)valueText;
       attackMaximumAmplification = tcstof(valueText, &afterValueText);
       if ((errno != 0) || (afterValueText[0] != T('\0'))
@@ -1066,12 +1067,14 @@ tmain(int argc, XML_Char **argv) {
                            ", xmlwf has been compiled without DTD support.\n"));
 #endif
       break;
+}
     }
     case T('b'): {
       const XML_Char *valueText = NULL;
       XMLWF_SHIFT_ARG_INTO(valueText, argc, argv, i, j);
 
       errno = 0;
+{
       XML_Char *afterValueText = (XML_Char *)valueText;
       attackThresholdBytes = tcstoull(valueText, &afterValueText, 10);
       if ((errno != 0) || (afterValueText[0] != T('\0'))) {
@@ -1088,6 +1091,7 @@ tmain(int argc, XML_Char **argv) {
 #endif
       break;
     }
+    }
     case T('\0'):
       if (j > 1) {
         i++;
-- 
2.30.2

