1diff --git a/source/common/ubidiwrt.cpp b/source/common/ubidiwrt.cpp 2index 969807c24376..209b140722cb 100644 3--- a/source/common/ubidiwrt.cpp 4+++ b/source/common/ubidiwrt.cpp 5@@ -501,7 +501,10 @@ ubidi_writeReordered(UBiDi *pBiDi, 6 destSize-=runLength; 7 8 if((pBiDi->isInverse) && 9- (/*run<runCount-1 &&*/ dirProps[logicalStart+runLength-1]!=L)) { 10+ (/*run<runCount-1 &&*/ 11+ runLength > 0 && // doWriteForward may return 0 if src 12+ // only include bidi control chars 13+ dirProps[logicalStart+runLength-1]!=L)) { 14 markFlag |= LRM_AFTER; 15 } 16 if (markFlag & LRM_AFTER) { 17@@ -632,7 +635,10 @@ ubidi_writeReordered(UBiDi *pBiDi, 18 } 19 destSize-=runLength; 20 21- if(/*run>0 &&*/ !(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) { 22+ if(/*run>0 &&*/ 23+ runLength > 0 && // doWriteForward may return 0 if src 24+ // only include bidi control chars 25+ !(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) { 26 if(destSize>0) { 27 *dest++=RLM_CHAR; 28 } 29