]> granicus.if.org Git - icu/commitdiff
ICU-11100 fix crash happening when there are many nested matching parentheses occurri...
authorMatitiahu Allouche <matitiahu.allouche@gmail.com>
Sun, 21 Sep 2014 06:38:01 +0000 (06:38 +0000)
committerMatitiahu Allouche <matitiahu.allouche@gmail.com>
Sun, 21 Sep 2014 06:38:01 +0000 (06:38 +0000)
Also change terminology from xxx_SIZE to xxx_COUNT to pursue change started in ticket #11054.

X-SVN-Rev: 36557

icu4c/source/common/ubidi.c
icu4c/source/common/ubidiimp.h

index b62b7df9081869cc31aa3155998745c1731e52be..8c0d64b039886930eb4cef319d47d0357576c949 100644 (file)
@@ -403,12 +403,12 @@ static UBool
 checkParaCount(UBiDi *pBiDi) {
     int32_t count=pBiDi->paraCount;
     if(pBiDi->paras==pBiDi->simpleParas) {
-        if(count<=SIMPLE_PARAS_SIZE)
+        if(count<=SIMPLE_PARAS_COUNT)
             return TRUE;
-        if(!getInitialParasMemory(pBiDi, SIMPLE_PARAS_SIZE * 2))
+        if(!getInitialParasMemory(pBiDi, SIMPLE_PARAS_COUNT * 2))
             return FALSE;
         pBiDi->paras=pBiDi->parasMemory;
-        uprv_memcpy(pBiDi->parasMemory, pBiDi->simpleParas, SIMPLE_PARAS_SIZE * sizeof(Para));
+        uprv_memcpy(pBiDi->parasMemory, pBiDi->simpleParas, SIMPLE_PARAS_COUNT * sizeof(Para));
         return TRUE;
     }
     if(!getInitialParasMemory(pBiDi, count * 2))
@@ -682,7 +682,7 @@ bracketInit(UBiDi *pBiDi, BracketData *bd) {
         bd->openingsCount=pBiDi->openingsSize / sizeof(Opening);
     } else {
         bd->openings=bd->simpleOpenings;
-        bd->openingsCount=SIMPLE_OPENINGS_SIZE;
+        bd->openingsCount=SIMPLE_OPENINGS_COUNT;
     }
     bd->isNumbersSpecial=bd->pBiDi->reorderingMode==UBIDI_REORDER_NUMBERS_SPECIAL ||
                          bd->pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL;
@@ -749,7 +749,7 @@ bracketAddOpening(BracketData *bd, UChar match, int32_t position) {
             return FALSE;
         if(bd->openings==bd->simpleOpenings)
             uprv_memcpy(pBiDi->openingsMemory, bd->simpleOpenings,
-                        SIMPLE_OPENINGS_SIZE * sizeof(Opening));
+                        SIMPLE_OPENINGS_COUNT * sizeof(Opening));
         bd->openings=pBiDi->openingsMemory;     /* may have changed */
         bd->openingsCount=pBiDi->openingsSize / sizeof(Opening);
     }
@@ -2167,6 +2167,9 @@ resolveImplicitLevels(UBiDi *pBiDi,
         } else {
             DirProp prop, prop1;
             prop=dirProps[i];
+            if(prop==B) {
+                pBiDi->isolateCount=-1; /* current isolates stack entry == none */
+            }
             if(inverseRTL) {
                 if(prop==AL) {
                     /* AL before EN does not make it AN */
@@ -2634,7 +2637,7 @@ ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
     }
 
     /* allocate isolate memory */
-    if(pBiDi->isolateCount<=SIMPLE_ISOLATES_SIZE)
+    if(pBiDi->isolateCount<=SIMPLE_ISOLATES_COUNT)
         pBiDi->isolates=pBiDi->simpleIsolates;
     else
         if((int32_t)(pBiDi->isolateCount*sizeof(Isolate))<=pBiDi->isolatesSize)
index 6db5b44c17a0e6685bb8a75d024c30f8bf9fe595..20ab9b994e93ebbe2f20eb91c70a35965a1ebfd2 100644 (file)
@@ -122,11 +122,11 @@ ubidi_getParaLevelAtIndex(const UBiDi *pBiDi, int32_t index);
                          (ubidi)->paraLevel : ubidi_getParaLevelAtIndex((ubidi), (index))))
 
 /* number of paras entries allocated initially without malloc */
-#define SIMPLE_PARAS_SIZE   10
+#define SIMPLE_PARAS_COUNT      10
 /* number of isolate entries allocated initially without malloc */
-#define SIMPLE_ISOLATES_SIZE 5
+#define SIMPLE_ISOLATES_COUNT   5
 /* number of isolate run entries for paired brackets allocated initially without malloc */
-#define SIMPLE_OPENINGS_SIZE 20
+#define SIMPLE_OPENINGS_COUNT   20
 
 #define CR  0x000D
 #define LF  0x000A
@@ -171,7 +171,7 @@ typedef struct IsoRun {
 typedef struct BracketData {
     UBiDi   *pBiDi;
     /* array of opening entries which should be enough in most cases; no malloc() */
-    Opening simpleOpenings[SIMPLE_OPENINGS_SIZE];
+    Opening simpleOpenings[SIMPLE_OPENINGS_COUNT];
     Opening *openings;                  /* pointer to current array of entries */
     int32_t openingsCount;              /* number of allocated entries */
     int32_t isoRunLast;                 /* index of last used entry */
@@ -345,7 +345,7 @@ struct UBiDi {
     Para *paras;
 
     /* for relatively short text, we only need a tiny array of paras (no malloc()) */
-    Para simpleParas[SIMPLE_PARAS_SIZE];
+    Para simpleParas[SIMPLE_PARAS_COUNT];
 
     /* fields for line reordering */
     int32_t runCount;     /* ==-1: runs not set up yet */
@@ -363,7 +363,7 @@ struct UBiDi {
     Isolate *isolates;
 
     /* for simple text, have a small stack (no malloc()) */
-    Isolate simpleIsolates[SIMPLE_ISOLATES_SIZE];
+    Isolate simpleIsolates[SIMPLE_ISOLATES_COUNT];
 
     /* for inverse Bidi with insertion of directional marks */
     InsertPoints insertPoints;