mirror of
https://github.com/dlang/dmd.git
synced 2025-04-28 06:00:13 +03:00
dcgcv.d add out of memory checks (#14535)
This commit is contained in:
parent
519653d17e
commit
b3dc2e0621
1 changed files with 16 additions and 38 deletions
|
@ -251,7 +251,9 @@ debtyp_t * debtyp_alloc(uint length)
|
||||||
length += pad;
|
length += pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
length < 0x10000 || assert(0);
|
if (length > ushort.max)
|
||||||
|
err_nomem();
|
||||||
|
|
||||||
const len = debtyp_t.sizeof - (d.data).sizeof + length;
|
const len = debtyp_t.sizeof - (d.data).sizeof + length;
|
||||||
debug
|
debug
|
||||||
{
|
{
|
||||||
|
@ -262,6 +264,8 @@ debug
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d = cast(debtyp_t *) malloc(debtyp_t.sizeof - (d.data).sizeof + length);
|
d = cast(debtyp_t *) malloc(debtyp_t.sizeof - (d.data).sizeof + length);
|
||||||
|
if (!d)
|
||||||
|
err_nomem();
|
||||||
}
|
}
|
||||||
d.length = cast(ushort)length;
|
d.length = cast(ushort)length;
|
||||||
if (pad)
|
if (pad)
|
||||||
|
@ -284,7 +288,7 @@ private void debtyp_free(debtyp_t *d)
|
||||||
//fflush(stdout);
|
//fflush(stdout);
|
||||||
debug
|
debug
|
||||||
{
|
{
|
||||||
assert(d.length < 0x10000);
|
assert(d.length <= ushort.max);
|
||||||
uint len = debtyp_t.sizeof - (d.data).sizeof + d.length;
|
uint len = debtyp_t.sizeof - (d.data).sizeof + d.length;
|
||||||
// assert((cast(char*)d)[len] == 0x2E);
|
// assert((cast(char*)d)[len] == 0x2E);
|
||||||
memset(d, 0x55, len);
|
memset(d, 0x55, len);
|
||||||
|
@ -325,56 +329,27 @@ void debtyp_check(debtyp_t* d) { }
|
||||||
@trusted
|
@trusted
|
||||||
idx_t cv_debtyp(debtyp_t *d)
|
idx_t cv_debtyp(debtyp_t *d)
|
||||||
{
|
{
|
||||||
ushort length;
|
|
||||||
uint hashi;
|
uint hashi;
|
||||||
|
|
||||||
assert(d);
|
assert(d);
|
||||||
length = d.length;
|
const length = d.length;
|
||||||
//printf("length = %3d\n",length);
|
//printf("length = %3d\n",length);
|
||||||
static if (SYMDEB_TDB)
|
static if (SYMDEB_TDB)
|
||||||
{
|
{
|
||||||
if (config.fulltypes == CVTDB)
|
if (config.fulltypes == CVTDB)
|
||||||
{
|
{
|
||||||
idx_t result;
|
|
||||||
|
|
||||||
static if (1)
|
|
||||||
{
|
|
||||||
assert(length);
|
assert(length);
|
||||||
debtyp_check(d);
|
debtyp_check(d);
|
||||||
result = tdb_typidx(&d.length);
|
const result = tdb_typidx(&d.length);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ubyte *buf;
|
|
||||||
|
|
||||||
// Allocate buffer
|
|
||||||
buf = malloc(6 + length);
|
|
||||||
if (!buf)
|
|
||||||
err_nomem(); // out of memory
|
|
||||||
|
|
||||||
// Fill the buffer
|
|
||||||
TOLONG(buf,cgcv.signature);
|
|
||||||
memcpy(buf + 4,cast(char *)d + uint.sizeof,2 + length);
|
|
||||||
|
|
||||||
static if (0)
|
|
||||||
{
|
|
||||||
{int i;
|
|
||||||
for (i=0;i<length;i++)
|
|
||||||
printf("%02x ",buf[6+i]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = tdb_typidx(buf,6 + length);
|
|
||||||
}
|
|
||||||
//printf("result = x%x\n",result);
|
//printf("result = x%x\n",result);
|
||||||
debtyp_free(d);
|
debtyp_free(d);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (length)
|
if (length)
|
||||||
{ uint hash;
|
{
|
||||||
|
uint hash = length;
|
||||||
hash = length;
|
|
||||||
if (length >= uint.sizeof)
|
if (length >= uint.sizeof)
|
||||||
{
|
{
|
||||||
// Hash consists of the sum of the first 4 bytes with the last 4 bytes
|
// Hash consists of the sum of the first 4 bytes with the last 4 bytes
|
||||||
|
@ -607,7 +582,8 @@ static if (SYMDEB_TDB)
|
||||||
pstate.STtdbtimestamp = tdb_gettimestamp();
|
pstate.STtdbtimestamp = tdb_gettimestamp();
|
||||||
size_t len = cv_stringbytes(ftdbname);
|
size_t len = cv_stringbytes(ftdbname);
|
||||||
ubyte *ds = (8 + len <= buf.sizeof) ? buf : cast(ubyte *) malloc(8 + len);
|
ubyte *ds = (8 + len <= buf.sizeof) ? buf : cast(ubyte *) malloc(8 + len);
|
||||||
assert(ds);
|
if (!ds)
|
||||||
|
err_nomem();
|
||||||
TOWORD(ds,6 + len);
|
TOWORD(ds,6 + len);
|
||||||
TOWORD(ds + 2,S_TDBNAME);
|
TOWORD(ds + 2,S_TDBNAME);
|
||||||
TOLONG(ds + 4,pstate.STtdbtimestamp);
|
TOLONG(ds + 4,pstate.STtdbtimestamp);
|
||||||
|
@ -2507,7 +2483,8 @@ else
|
||||||
// Length of record
|
// Length of record
|
||||||
length = 2 + 2 + 4 * 3 + _tysize[TYint] * 4 + 2 + cgcv.sz_idx + 1;
|
length = 2 + 2 + 4 * 3 + _tysize[TYint] * 4 + 2 + cgcv.sz_idx + 1;
|
||||||
debsym = (length + len <= (buf).sizeof) ? buf.ptr : cast(ubyte *) malloc(length + len);
|
debsym = (length + len <= (buf).sizeof) ? buf.ptr : cast(ubyte *) malloc(length + len);
|
||||||
assert(debsym);
|
if (!debsym)
|
||||||
|
err_nomem();
|
||||||
memset(debsym,0,length + len);
|
memset(debsym,0,length + len);
|
||||||
|
|
||||||
// Symbol type
|
// Symbol type
|
||||||
|
@ -2586,7 +2563,8 @@ else
|
||||||
}
|
}
|
||||||
len = cast(uint)strlen(id);
|
len = cast(uint)strlen(id);
|
||||||
debsym = (39 + IDOHD + len <= (buf).sizeof) ? buf.ptr : cast(ubyte *) malloc(39 + IDOHD + len);
|
debsym = (39 + IDOHD + len <= (buf).sizeof) ? buf.ptr : cast(ubyte *) malloc(39 + IDOHD + len);
|
||||||
assert(debsym);
|
if (!debsym)
|
||||||
|
err_nomem();
|
||||||
switch (s.Sclass)
|
switch (s.Sclass)
|
||||||
{
|
{
|
||||||
case SC.parameter:
|
case SC.parameter:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue