@@ -384,6 +384,8 @@ STOID Mold_String_Series(REBVAL *value, REB_MOLD *mold)
384
384
return ;
385
385
}
386
386
387
+ CHECK_MOLD_LIMIT (mold , len );
388
+
387
389
Sniff_String (ser , idx , & sf );
388
390
if (!GET_MOPT (mold , MOPT_ANSI_ONLY )) sf .paren = 0 ;
389
391
@@ -415,7 +417,7 @@ STOID Mold_String_Series(REBVAL *value, REB_MOLD *mold)
415
417
416
418
* dp ++ = '{' ;
417
419
418
- for (n = idx ; n < VAL_TAIL ( value ); n ++ ) {
420
+ for (n = idx ; n < ( len + idx ); n ++ ) {
419
421
420
422
c = uni ? up [n ] : (REBUNI )(bp [n ]);
421
423
switch (c ) {
@@ -554,18 +556,20 @@ STOID Mold_Handle(REBVAL *value, REB_MOLD *mold)
554
556
REBSER * out ;
555
557
REBOOL indented = !GET_MOPT (mold , MOPT_INDENT );
556
558
559
+ CHECK_MOLD_LIMIT (mold , len );
560
+
557
561
switch (Get_System_Int (SYS_OPTIONS , OPTIONS_BINARY_BASE , 16 )) {
558
562
default :
559
563
case 16 :
560
- out = Encode_Base16 (value , 0 , indented && len > 32 );
564
+ out = Encode_Base16 (value , 0 , len , indented && len > 32 );
561
565
break ;
562
566
case 64 :
563
567
Append_Bytes (mold -> series , "64" );
564
- out = Encode_Base64 (value , 0 , indented && len > 64 , FALSE);
568
+ out = Encode_Base64 (value , 0 , len , indented && len > 64 , FALSE);
565
569
break ;
566
570
case 2 :
567
571
Append_Byte (mold -> series , '2' );
568
- out = Encode_Base2 (value , 0 , indented && len > 8 );
572
+ out = Encode_Base2 (value , 0 , len , indented && len > 8 );
569
573
break ;
570
574
}
571
575
@@ -632,6 +636,8 @@ STOID Mold_Block_Series(REB_MOLD *mold, REBSER *series, REBCNT index, REBYTE *se
632
636
633
637
value = BLK_SKIP (series , index );
634
638
while (NOT_END (value )) {
639
+ // check if we can end sooner with molding..
640
+ if (MOLD_HAS_LIMIT (mold ) && MOLD_OVER_LIMIT (mold )) return ;
635
641
if (VAL_GET_LINE (value )) {
636
642
if (indented && (sep [1 ] || line_flag )) New_Indented_Line (mold );
637
643
had_lines = TRUE;
@@ -955,12 +961,16 @@ STOID Mold_Object(REBVAL *value, REB_MOLD *mold)
955
961
Append_Bytes (mold -> series , ": " );
956
962
if (IS_WORD (vals + n ) && !GET_MOPT (mold , MOPT_MOLD_ALL )) Append_Byte (mold -> series , '\'' );
957
963
Mold_Value (mold , vals + n , TRUE);
964
+ if (MOLD_HAS_LIMIT (mold ) && MOLD_OVER_LIMIT (mold )) {
965
+ // early escape
966
+ Remove_Last (MOLD_LOOP );
967
+ return ;
968
+ }
958
969
}
959
970
}
960
971
mold -> indent -- ;
961
972
if (indented ) New_Indented_Line (mold );
962
973
Append_Byte (mold -> series , ']' );
963
-
964
974
End_Mold (mold );
965
975
Remove_Last (MOLD_LOOP );
966
976
}
@@ -1061,7 +1071,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
1061
1071
1062
1072
// Forming a string:
1063
1073
if (!molded ) {
1064
- Insert_String (ser , -1 , VAL_SERIES (value ), VAL_INDEX (value ), VAL_LEN (value ), 0 );
1074
+ Insert_String (ser , NO_LIMIT , VAL_SERIES (value ), VAL_INDEX (value ), VAL_LEN (value ), 0 );
1065
1075
return ;
1066
1076
}
1067
1077
@@ -1138,7 +1148,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
1138
1148
Mold_Binary (value , mold );
1139
1149
}
1140
1150
else {
1141
- Emit (mold , "E" , Encode_Base16 (value , 0 , FALSE));
1151
+ Emit (mold , "E" , Encode_Base16 (value , 0 , NO_LIMIT , FALSE));
1142
1152
}
1143
1153
break ;
1144
1154
@@ -1194,10 +1204,10 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
1194
1204
1195
1205
case REB_BLOCK :
1196
1206
case REB_PAREN :
1197
- if (!molded )
1198
- Form_Block_Series (VAL_SERIES (value ), VAL_INDEX (value ), mold , 0 );
1199
- else
1207
+ if (molded )
1200
1208
Mold_Block (value , mold );
1209
+ else
1210
+ Form_Block_Series (VAL_SERIES (value ), VAL_INDEX (value ), mold , 0 );
1201
1211
break ;
1202
1212
1203
1213
case REB_PATH :
@@ -1445,6 +1455,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
1445
1455
else if (len < 0 ) len = 0 ;
1446
1456
}
1447
1457
mold -> digits = len ;
1458
+ mold -> limit = NO_LIMIT ;
1448
1459
}
1449
1460
1450
1461
@@ -1461,6 +1472,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
1461
1472
REB_MOLD mo = {0 };
1462
1473
1463
1474
Reset_Mold (& mo );
1475
+ mo .limit = limit ;
1464
1476
1465
1477
Mold_Value (& mo , value , mold );
1466
1478
0 commit comments