Browse Source

dont use dynamic size stack arrays

Patrick Brosi 6 years ago
parent
commit
f8e187d07f
1 changed files with 6 additions and 3 deletions
  1. 6 3
      File.cpp

+ 6 - 3
File.cpp

@@ -333,7 +333,7 @@ std::string File::decode(const char* str) {
333
   const char* c = strchr(str, '&');
333
   const char* c = strchr(str, '&');
334
   if (!c) return str;
334
   if (!c) return str;
335
 
335
 
336
-  char decRet[strlen(str) + 1];
336
+  char* decRet = new char[strlen(str) + 1];
337
   const char* last = str;
337
   const char* last = str;
338
   char* dstPt = decRet;
338
   char* dstPt = decRet;
339
 
339
 
@@ -358,7 +358,7 @@ std::string File::decode(const char* str) {
358
     } else {
358
     } else {
359
       const char* e = strchr(c, ';');
359
       const char* e = strchr(c, ';');
360
       if (e) {
360
       if (e) {
361
-        char ent[e - 1 - c + 1];
361
+        char* ent = new char[e - 1 - c + 1];
362
         memcpy(ent, c + 1, e - 1 - c);
362
         memcpy(ent, c + 1, e - 1 - c);
363
         ent[e - 1 - c] = 0;
363
         ent[e - 1 - c] = 0;
364
         const auto it = xml::ENTITIES.find(ent);
364
         const auto it = xml::ENTITIES.find(ent);
@@ -368,12 +368,15 @@ std::string File::decode(const char* str) {
368
           dstPt += strlen(utf8);
368
           dstPt += strlen(utf8);
369
           last += strlen(ent) + 2;
369
           last += strlen(ent) + 2;
370
         }
370
         }
371
+        delete[] ent;
371
       }
372
       }
372
     }
373
     }
373
   }
374
   }
374
 
375
 
375
   strcpy(dstPt, last);
376
   strcpy(dstPt, last);
376
-  return decRet;
377
+  std::string ret(decRet);
378
+  delete[] decRet;
379
+  return ret;
377
 }
380
 }
378
 
381
 
379
 // _____________________________________________________________________________
382
 // _____________________________________________________________________________