Skip to content

Commit

Permalink
backend: remove alloca() calls from cgcv.c
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 24, 2015
1 parent 2fdfedb commit 49916dc
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/backend/cgcv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 1984-1998 by Symantec
// Copyright (C) 2000-2013 by Digital Mars
// Copyright (C) 2000-2015 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
Expand All @@ -17,14 +17,6 @@
#include <time.h>
#include <stdlib.h>

#if _WIN32 || __linux__
#include <malloc.h>
#endif

#if __sun
#include <alloca.h>
#endif

#include "cc.h"
#include "type.h"
#include "code.h"
Expand Down Expand Up @@ -528,17 +520,19 @@ void cv_init()
// Put out S_TDBNAME record
if (config.fulltypes == CVTDB)
{
unsigned char *ds;
size_t len;
unsigned char buf[50];

pstate.STtdbtimestamp = tdb_gettimestamp();
len = cv_stringbytes(ftdbname);
ds = (unsigned char *) alloca(8 + len);
size_t len = cv_stringbytes(ftdbname);
unsigned char *ds = (8 + len <= sizeof(buf)) ? buf : (unsigned char *) malloc(8 + len);
assert(ds);
TOWORD(ds,6 + len);
TOWORD(ds + 2,S_TDBNAME);
TOLONG(ds + 4,pstate.STtdbtimestamp);
cv_namestring(ds + 8,ftdbname);
objmod->write_bytes(SegData[DEBSYM],8 + len,ds);
if (ds != buf)
free(ds);
}
#endif
}
Expand Down Expand Up @@ -2220,7 +2214,8 @@ STATIC void cv4_outsym(symbol *s)
unsigned u;
tym_t tym;
const char *id;
unsigned char __ss *debsym;
unsigned char *debsym = NULL;
unsigned char buf[64];

//dbg_printf("cv4_outsym(%s)\n",s->Sident);
symbol_debug(s);
Expand Down Expand Up @@ -2257,7 +2252,8 @@ STATIC void cv4_outsym(symbol *s)

// Length of record
length = 2 + 2 + 4 * 3 + intsize * 4 + 2 + cgcv.sz_idx + 1;
debsym = (unsigned char __ss *) alloca(length + len);
debsym = (length + len <= sizeof(buf)) ? buf : (unsigned char *) malloc(length + len);
assert(debsym);
memset(debsym,0,length + len);

// Symbol type
Expand Down Expand Up @@ -2332,7 +2328,8 @@ STATIC void cv4_outsym(symbol *s)
id = prettyident(s);
#endif
len = strlen(id);
debsym = (unsigned char __ss *) alloca(39 + IDOHD + len);
debsym = (39 + IDOHD + len <= sizeof(buf)) ? buf : (unsigned char *) malloc(39 + IDOHD + len);
assert(debsym);
switch (s->Sclass)
{
case SCparameter:
Expand Down Expand Up @@ -2395,7 +2392,7 @@ STATIC void cv4_outsym(symbol *s)
// Common blocks have a non-zero Sxtrnnum and an UNKNOWN seg
if (!(s->Sxtrnnum && s->Sseg == UNKNOWN)) // if it's not really a common block
{
return;
goto Lret;
}
/* FALL-THROUGH */
case SCglobal:
Expand Down Expand Up @@ -2466,7 +2463,7 @@ STATIC void cv4_outsym(symbol *s)
objmod->write_long(DEBSYM,offset + fixoff,s->Soffset,
cgcv.LCFDpointer + fd,idx1,idx2);
}
return;
goto Lret;

#if 1
case SCtypedef:
Expand All @@ -2475,13 +2472,13 @@ STATIC void cv4_outsym(symbol *s)

case SCstruct:
if (s->Sstruct->Sflags & STRnotagname)
return;
goto Lret;
goto L4;

case SCenum:
#if SCPP
if (CPP && s->Senum->SEflags & SENnotagname)
return;
goto Lret;
#endif
L4:
// Output a 'user-defined type' for the tag name
Expand All @@ -2506,11 +2503,14 @@ STATIC void cv4_outsym(symbol *s)
break;
#endif
default:
return;
goto Lret;
}
assert(length <= 40 + len);
objmod->write_bytes(SegData[DEBSYM],length,debsym);
}
Lret:
if (debsym != buf)
free(debsym);
}

/******************************************
Expand Down

0 comments on commit 49916dc

Please sign in to comment.