Skip to content

Commit e6381ef

Browse files
authored
Fix escapes hidden by dmd nested function / lambda holes (#11122)
1 parent 0890f5e commit e6381ef

5 files changed

Lines changed: 20 additions & 23 deletions

File tree

‎std/datetime/systime.d‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10447,13 +10447,13 @@ if (isRandomAccessRange!R && hasSlicing!R && hasLength!R &&
1044710447
import std.traits : EnumMembers, isArray;
1044810448
import std.typecons : Rebindable;
1044910449

10450-
void stripAndCheckLen(R valueBefore, size_t minLen, size_t line = __LINE__)
10450+
void stripAndCheckLen(size_t start, size_t minLen, size_t line = __LINE__)
1045110451
{
10452-
value = _stripCFWS(valueBefore);
10452+
value = _stripCFWS(value[start .. value.length]);
1045310453
if (value.length < minLen)
1045410454
throw new DateTimeException("date-time value too short", __FILE__, line);
1045510455
}
10456-
stripAndCheckLen(value, "7Dec1200:00A".length);
10456+
stripAndCheckLen(0, "7Dec1200:00A".length);
1045710457

1045810458
static if (isArray!R && (is(ElementEncodingType!R == char) || is(ElementEncodingType!R == ubyte)))
1045910459
{
@@ -10488,18 +10488,18 @@ if (isRandomAccessRange!R && hasSlicing!R && hasLength!R &&
1048810488
}
1048910489
default: throw new DateTimeException(format("Invalid day-of-week: %s", dowStr));
1049010490
}
10491-
afterDoW: stripAndCheckLen(value[3 .. value.length], ",7Dec1200:00A".length);
10491+
afterDoW: stripAndCheckLen(3, ",7Dec1200:00A".length);
1049210492
if (value[0] != ',')
1049310493
throw new DateTimeException("day-of-week missing comma");
10494-
stripAndCheckLen(value[1 .. value.length], "7Dec1200:00A".length);
10494+
stripAndCheckLen(1, "7Dec1200:00A".length);
1049510495
}
1049610496

1049710497
// day
1049810498
immutable digits = isDigit(value[1]) ? 2 : 1;
1049910499
immutable day = _convDigits!short(value[0 .. digits]);
1050010500
if (day == -1)
1050110501
throw new DateTimeException("Invalid day");
10502-
stripAndCheckLen(value[digits .. value.length], "Dec1200:00A".length);
10502+
stripAndCheckLen(digits, "Dec1200:00A".length);
1050310503

1050410504
// month
1050510505
Month month;
@@ -10518,7 +10518,7 @@ afterDoW: stripAndCheckLen(value[3 .. value.length], ",7Dec1200:00A".length);
1051810518
}
1051910519
default: throw new DateTimeException(format("Invalid month: %s", monStr));
1052010520
}
10521-
afterMon: stripAndCheckLen(value[3 .. value.length], "1200:00A".length);
10521+
afterMon: stripAndCheckLen(3, "1200:00A".length);
1052210522
}
1052310523

1052410524
// year
@@ -10545,29 +10545,29 @@ afterMon: stripAndCheckLen(value[3 .. value.length], "1200:00A".length);
1054510545
else
1054610546
throw new DateTimeException("Invalid year. Cannot be earlier than 1900.");
1054710547
}
10548-
stripAndCheckLen(value[yearLen .. value.length], "00:00A".length);
10548+
stripAndCheckLen(yearLen, "00:00A".length);
1054910549

1055010550
// hour
1055110551
immutable hour = _convDigits!short(value[0 .. 2]);
10552-
stripAndCheckLen(value[2 .. value.length], ":00A".length);
10552+
stripAndCheckLen(2, ":00A".length);
1055310553
if (value[0] != ':')
1055410554
throw new DateTimeException("Invalid hour");
10555-
stripAndCheckLen(value[1 .. value.length], "00A".length);
10555+
stripAndCheckLen(1, "00A".length);
1055610556

1055710557
// minute
1055810558
immutable minute = _convDigits!short(value[0 .. 2]);
10559-
stripAndCheckLen(value[2 .. value.length], "A".length);
10559+
stripAndCheckLen(2, "A".length);
1056010560

1056110561
// second
1056210562
short second;
1056310563
if (value[0] == ':')
1056410564
{
10565-
stripAndCheckLen(value[1 .. value.length], "00A".length);
10565+
stripAndCheckLen(1, "00A".length);
1056610566
second = _convDigits!short(value[0 .. 2]);
1056710567
// this is just if/until SysTime is sorted out to fully support leap seconds
1056810568
if (second == 60)
1056910569
second = 59;
10570-
stripAndCheckLen(value[2 .. value.length], "A".length);
10570+
stripAndCheckLen(2, "A".length);
1057110571
}
1057210572

1057310573
immutable(TimeZone) parseTZ(int sign)

‎std/experimental/allocator/building_blocks/kernighan_ritchie.d‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
155155
if (leftover >= Node.sizeof)
156156
{
157157
// There's room for another node
158-
auto newNode = (() @trusted => cast(Node*) ((cast(ubyte*) &this) + bytes))();
158+
auto newNode = (() @trusted => cast(Node*) (cast(size_t) &this + bytes))();
159159
newNode.size = leftover;
160160
newNode.next = next == &this ? newNode : next;
161161
assert(next);

‎std/experimental/allocator/package.d‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,10 +2108,10 @@ version (StdUnittest)
21082108

21092109
void test(A)(auto ref A alloc)
21102110
{
2111+
auto arr2 = arr;
21112112
ForcedInputRange!int r;
21122113
long[] a = alloc.makeArray!long(r);
21132114
assert(a.length == 0 && a.ptr is null);
2114-
auto arr2 = arr;
21152115
r.array = () @trusted { return &arr2; } ();
21162116
a = alloc.makeArray!long(r);
21172117
assert(a.length == 10);

‎std/internal/math/biguintcore.d‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ private int slowHighestPowerBelowUintMax(uint x) pure nothrow @safe
15141514
* Returns:
15151515
* unique memory
15161516
*/
1517-
BigDigit [] sub(const scope BigDigit [] x, const scope BigDigit [] y, bool *negative)
1517+
BigDigit [] sub(const scope BigDigit [] x, const scope BigDigit [] y, scope bool *negative)
15181518
pure nothrow @safe
15191519
{
15201520
if (x.length == y.length)
@@ -1606,7 +1606,7 @@ BigDigit [] add(const scope BigDigit [] a, const scope BigDigit [] b) pure nothr
16061606

16071607
/** return x + y
16081608
*/
1609-
BigDigit [] addInt(const BigDigit[] x, ulong y) @safe pure nothrow
1609+
BigDigit [] addInt(const scope BigDigit[] x, ulong y) @safe pure nothrow
16101610
{
16111611
uint hi = cast(uint)(y >>> 32);
16121612
uint lo = cast(uint)(y& 0xFFFF_FFFF);
@@ -1633,7 +1633,7 @@ BigDigit [] addInt(const BigDigit[] x, ulong y) @safe pure nothrow
16331633
/** Return x - y.
16341634
* x must be greater than y.
16351635
*/
1636-
BigDigit [] subInt(const BigDigit[] x, ulong y) pure nothrow @safe
1636+
BigDigit [] subInt(const scope BigDigit[] x, ulong y) pure nothrow @safe
16371637
{
16381638
uint hi = cast(uint)(y >>> 32);
16391639
uint lo = cast(uint)(y & 0xFFFF_FFFF);

‎std/range/package.d‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ if (Ranges.length > 0 &&
10371037
frontIndex = source.length;
10381038
static if (bidirectional) backIndex = 0;
10391039

1040-
foreach (i, ref v; input) source[i] = v;
1040+
static foreach (i; 0 .. R.length) source[i] = input[i];
10411041

10421042
// We do this separately to avoid invoking `empty` needlessly.
10431043
// While not recommended, a range may depend on side effects of
@@ -1096,10 +1096,7 @@ if (Ranges.length > 0 &&
10961096
// TODO: this has the constructor needlessly refind
10971097
// frontIndex and backIndex. It'd be better to just copy
10981098
// those from `.this`.
1099-
auto saveResult =
1100-
Result(staticMap!(saveI, aliasSeqOf!(R.length.iota)));
1101-
1102-
return saveResult;
1099+
return Result(staticMap!(saveI, aliasSeqOf!(R.length.iota)));
11031100
}
11041101
}
11051102

0 commit comments

Comments
 (0)