Skip to content

Commit

Permalink
Fix cases where goto skips variable initialization found by fixing is…
Browse files Browse the repository at this point in the history
…sue 602
  • Loading branch information
yebblies committed Dec 3, 2013
1 parent b8554bc commit 62a02a1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 54 deletions.
45 changes: 22 additions & 23 deletions src/expression.c
Expand Up @@ -1420,16 +1420,18 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
if (tf->varargs == 2 && i + 1 == nparams)
{
//printf("\t\tvarargs == 2, p->type = '%s'\n", p->type->toChars());
MATCH m;
if ((m = arg->implicitConvTo(p->type)) != MATCHnomatch)
{
if (p->type->nextOf() && arg->implicitConvTo(p->type->nextOf()) >= m)
goto L2;
else if (nargs != nparams)
{ error(loc, "expected %llu function arguments, not %llu", (ulonglong)nparams, (ulonglong)nargs);
return Type::terror;
MATCH m;
if ((m = arg->implicitConvTo(p->type)) != MATCHnomatch)
{
if (p->type->nextOf() && arg->implicitConvTo(p->type->nextOf()) >= m)
goto L2;
else if (nargs != nparams)
{ error(loc, "expected %llu function arguments, not %llu", (ulonglong)nparams, (ulonglong)nargs);
return Type::terror;
}
goto L1;
}
goto L1;
}
L2:
Type *tb = p->type->toBasetype();
Expand Down Expand Up @@ -10235,6 +10237,7 @@ Expression *SliceExp::semantic(Scope *sc)
e = this;

Type *t = e1->type->toBasetype();
AggregateDeclaration *ad = isAggregate(t);
if (t->ty == Tpointer)
{
if (!lwr || !upr)
Expand All @@ -10250,7 +10253,7 @@ Expression *SliceExp::semantic(Scope *sc)
else if (t->ty == Tsarray)
{
}
else if (AggregateDeclaration *ad = isAggregate(t))
else if (ad)
{
if (search_function(ad, Id::slice))
{
Expand Down Expand Up @@ -10290,7 +10293,16 @@ Expression *SliceExp::semantic(Scope *sc)
else if (t == Type::terror)
goto Lerr;
else
goto Lerror;
{
Lerror:
if (e1->op == TOKerror)
return e1;
error("%s cannot be sliced with []",
t->ty == Tvoid ? e1->toChars() : t->toChars());
Lerr:
e = new ErrorExp();
return e;
}

{
Scope *sc2 = sc;
Expand Down Expand Up @@ -10387,19 +10399,6 @@ Expression *SliceExp::semantic(Scope *sc)
type = e1->type;

return e;

Lerror:
if (e1->op == TOKerror)
return e1;
char *s;
if (t->ty == Tvoid)
s = e1->toChars();
else
s = t->toChars();
error("%s cannot be sliced with []", s);
Lerr:
e = new ErrorExp();
return e;
}

void SliceExp::checkEscape()
Expand Down
17 changes: 6 additions & 11 deletions src/inifile.c
Expand Up @@ -184,24 +184,18 @@ const char *inifile(const char *argv0x, const char *inifilex, const char *envsec
break;
}

// The line is file.buffer[linestart..i]
char *line;
size_t len;
char *pn;

line = (char *)&file.buffer[linestart];
len = i - linestart;

buf.reset();

// First, expand the macros.
// Macros are bracketed by % characters.

for (size_t k = 0; k < len; k++)
for (size_t k = 0; k < i - linestart; k++)
{
// The line is file.buffer[linestart..i]
char *line = (char *)&file.buffer[linestart];
if (line[k] == '%')
{
for (size_t j = k + 1; j < len; j++)
for (size_t j = k + 1; j < i - linestart; j++)
{
if (line[j] == '%')
{
Expand Down Expand Up @@ -264,6 +258,7 @@ const char *inifile(const char *argv0x, const char *inifilex, const char *envsec

case '[': // look for [Environment]
p = skipspace(p + 1);
char *pn;
for (pn = p; isalnum((utf8_t)*pn); pn++)
;
if (pn - p == envsectionnamelen &&
Expand All @@ -278,7 +273,7 @@ const char *inifile(const char *argv0x, const char *inifilex, const char *envsec
default:
if (envsection)
{
pn = p;
char *pn = p;

// Convert name to upper case;
// remove spaces bracketing =
Expand Down
4 changes: 2 additions & 2 deletions src/interpret.c
Expand Up @@ -1796,11 +1796,11 @@ Expression *TryCatchStatement::interpret(InterState *istate)
InterState istatex = *istate;
istatex.start = istate->gotoTarget; // set starting statement
istatex.gotoTarget = NULL;
Expression *ex = ca->handler->interpret(&istatex);
Expression *eh = ca->handler->interpret(&istatex);
if (!istatex.start)
{
istate->gotoTarget = NULL;
e = ex;
e = eh;
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/mtype.c
Expand Up @@ -7186,7 +7186,10 @@ void TypeTypeof::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
{
inuse = 2;
error(loc, "circular typeof definition");
goto Lerr;
Lerr:
*pt = Type::terror;
inuse--;
return;
}
inuse++;

Expand Down Expand Up @@ -7270,11 +7273,6 @@ void TypeTypeof::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
(*pt) = (*pt)->addMod(mod);
inuse--;
return;

Lerr:
*pt = Type::terror;
inuse--;
return;
}

Type *TypeTypeof::semantic(Loc loc, Scope *sc)
Expand Down
9 changes: 4 additions & 5 deletions src/optimize.c
Expand Up @@ -569,7 +569,10 @@ Expression *CastExp::optimize(int result, bool keepLvalue)
e1->type->implicitConvTo(type) >= MATCHconst)
{
if (X) printf(" returning2 %s\n", e1->toChars());
goto L1;
L1: // Returning e1 with changing its type
Expression *e = (e1old == e1 ? e1->copy() : e1);
e->type = type;
return e;
}

/* The first test here is to prevent infinite loops
Expand Down Expand Up @@ -628,10 +631,6 @@ Expression *CastExp::optimize(int result, bool keepLvalue)
e = this;
if (X) printf(" returning6 %s\n", e->toChars());
return e;
L1: // Returning e1 with changing its type
e = (e1old == e1 ? e1->copy() : e1);
e->type = type;
return e;
#undef X
}

Expand Down
12 changes: 5 additions & 7 deletions src/template.c
Expand Up @@ -2349,7 +2349,11 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
if (td->semanticRun == PASSinit)
{
::error(loc, "forward reference to template %s", td->toChars());
goto Lerror;
Lerror:
m->lastf = NULL;
m->count = 0;
m->last = MATCHnomatch;
return 1;
}
FuncDeclaration *f;
f = td->onemember ? td->onemember/*->toAlias()*/->isFuncDeclaration() : NULL;
Expand Down Expand Up @@ -2515,12 +2519,6 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
continue;
}
return 0;

Lerror:
m->lastf = NULL;
m->count = 0;
m->last = MATCHnomatch;
return 1;
}
};
ParamDeduce p;
Expand Down

0 comments on commit 62a02a1

Please sign in to comment.