Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e8c760f

Browse files
committedNov 22, 2013
Merge pull request #665 from yebblies/gotoskipinit
Fix cases where goto skips initialization of variables
2 parents f79eea6 + b416416 commit e8c760f

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed
 

‎src/rt/aaA.d

+18-16
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,25 @@ body
182182
pe = &e.next;
183183
}
184184

185-
// Not found, create new elem
186-
//printf("create new one\n");
187-
size_t size = Entry.sizeof + aligntsize(keytitsize) + valuesize;
188-
e = cast(Entry *) GC.malloc(size);
189-
e.next = null;
190-
e.hash = key_hash;
191-
ubyte* ptail = cast(ubyte*)(e + 1);
192-
memcpy(ptail, pkey, keytitsize);
193-
memset(ptail + aligntsize(keytitsize), 0, valuesize); // zero value
194-
*pe = e;
195-
196-
auto nodes = ++aa.impl.nodes;
197-
//printf("length = %d, nodes = %d\n", aa.a.buckets.length, nodes);
198-
if (nodes > aa.impl.buckets.length * 4)
199185
{
200-
//printf("rehash\n");
201-
_aaRehash(aa,keyti);
186+
// Not found, create new elem
187+
//printf("create new one\n");
188+
size_t size = Entry.sizeof + aligntsize(keytitsize) + valuesize;
189+
e = cast(Entry *) GC.malloc(size);
190+
e.next = null;
191+
e.hash = key_hash;
192+
ubyte* ptail = cast(ubyte*)(e + 1);
193+
memcpy(ptail, pkey, keytitsize);
194+
memset(ptail + aligntsize(keytitsize), 0, valuesize); // zero value
195+
*pe = e;
196+
197+
auto nodes = ++aa.impl.nodes;
198+
//printf("length = %d, nodes = %d\n", aa.a.buckets.length, nodes);
199+
if (nodes > aa.impl.buckets.length * 4)
200+
{
201+
//printf("rehash\n");
202+
_aaRehash(aa,keyti);
203+
}
202204
}
203205

204206
Lret:

‎src/rt/lifetime.d

+12-10
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ body
630630
mov EAX, newcapacity;
631631
mul EAX, size;
632632
mov reqsize, EAX;
633-
jc Loverflow;
633+
jnc Lcontinue;
634634
}
635635
}
636636
else version (D_InlineAsm_X86_64)
@@ -642,16 +642,20 @@ body
642642
mov RAX, newcapacity;
643643
mul RAX, size;
644644
mov reqsize, RAX;
645-
jc Loverflow;
645+
jnc Lcontinue;
646646
}
647647
}
648648
else
649649
{
650650
size_t reqsize = size * newcapacity;
651651

652-
if (newcapacity > 0 && reqsize / newcapacity != size)
653-
goto Loverflow;
652+
if (newcapacity == 0 || reqsize / newcapacity == size)
653+
goto Lcontinue;
654654
}
655+
Loverflow:
656+
onOutOfMemoryError();
657+
assert(0);
658+
Lcontinue:
655659

656660
// step 2, get the actual "allocated" size. If the allocated size does not
657661
// match what we expect, then we will need to reallocate anyways.
@@ -766,10 +770,6 @@ body
766770

767771
curcapacity = info.size - arraypad;
768772
return curcapacity / size;
769-
770-
Loverflow:
771-
onOutOfMemoryError();
772-
assert(0);
773773
}
774774

775775
/**
@@ -1869,8 +1869,10 @@ byte[] _d_arrayappendcTX(const TypeInfo ti, ref byte[] px, size_t n)
18691869
else
18701870
{
18711871
// not appendable or is null
1872-
auto allocsize = newCapacity(newlength, sizeelem);
1873-
info = gc_qalloc(allocsize + __arrayPad(allocsize), (info.base ? info.attr : !(ti.next.flags & 1) ? BlkAttr.NO_SCAN : 0) | BlkAttr.APPENDABLE);
1872+
{
1873+
auto allocsize = newCapacity(newlength, sizeelem);
1874+
info = gc_qalloc(allocsize + __arrayPad(allocsize), (info.base ? info.attr : !(ti.next.flags & 1) ? BlkAttr.NO_SCAN : 0) | BlkAttr.APPENDABLE);
1875+
}
18741876
L2:
18751877
__setArrayAllocLength(info, newsize, isshared);
18761878
if(!isshared)

0 commit comments

Comments
 (0)
Please sign in to comment.