Skip to content

Commit

Permalink
Merge pull request #5068 from CyberShadow/valgrind-20150912
Browse files Browse the repository at this point in the history
Minor memory-safety fixes (Valgrind-identified problems, debug bounds checks)
  • Loading branch information
yebblies committed Sep 22, 2015
2 parents 73d7f53 + d7091d5 commit 0284ca0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/backend/machobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,9 @@ void MachObj::addrel(int seg, targ_size_t offset, symbol *targsym,
unsigned targseg, int rtype, int val)
{
Relocation rel;
#ifdef DEBUG
memset(&rel, 0, sizeof(rel));
#endif
rel.offset = offset;
rel.targsym = targsym;
rel.targseg = targseg;
Expand Down
16 changes: 15 additions & 1 deletion src/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,21 @@ extern (C++) UnionExp Div(Loc loc, Type type, Expression e1, Expression e2)
{
if (e1.type.isreal())
{
emplaceExp!(RealExp)(&ue, loc, e1.toReal() / e2.toReal(), type);
version (all)
{
// Work around redundant REX.W prefix breaking Valgrind
// when built with affected versions of DMD.
// https://issues.dlang.org/show_bug.cgi?id=14952
// This can be removed once compiling with DMD 2.068 or
// older is no longer supported.
d_float80 r1 = e1.toReal();
d_float80 r2 = e2.toReal();
emplaceExp!(RealExp)(&ue, loc, r1 / r2, type);
}
else
{
emplaceExp!(RealExp)(&ue, loc, e1.toReal() / e2.toReal(), type);
}
return ue;
}
r = e2.toReal();
Expand Down
2 changes: 1 addition & 1 deletion src/dmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public:
scope Mangler v = new Mangler(&buf2);
v.paramsToDecoBuffer(t.arguments);
int len = cast(int)buf2.offset;
buf.printf("%d%.*s", len, len, buf2.extractData());
buf.printf("%d%.*s", len, len, buf2.extractString());
}

override void visit(TypeNull t)
Expand Down
2 changes: 1 addition & 1 deletion src/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern (C++) void genhdrfile(Module m)
toCBuffer(m, &buf, &hgs);
// Transfer image to file
m.hdrfile.setbuffer(buf.data, buf.offset);
buf.data = null;
buf.extractData();
ensurePathToNameExists(Loc(), m.hdrfile.toChars());
writeFile(m.loc, m.hdrfile);
}
Expand Down
21 changes: 19 additions & 2 deletions src/optimize.d
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,25 @@ extern (C++) Expression Expression_optimize(Expression e, int result, bool keepL
return;
}
// If e2 *could* have been an integer, make it one.
if (e.e2.op == TOKfloat64 && (e.e2.toReal() == cast(sinteger_t)e.e2.toReal()))
e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64);
if (e.e2.op == TOKfloat64)
{
version (all)
{
// Work around redundant REX.W prefix breaking Valgrind
// when built with affected versions of DMD.
// https://issues.dlang.org/show_bug.cgi?id=14952
// This can be removed once compiling with DMD 2.068 or
// older is no longer supported.
d_float80 r = e.e2.toReal();
if (r == cast(sinteger_t)r)
e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64);
}
else
{
if (e.e2.toReal() == cast(sinteger_t)e.e2.toReal())
e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64);
}
}
if (e.e1.isConst() == 1 && e.e2.isConst() == 1)
{
Expression ex = Pow(e.loc, e.type, e.e1, e.e2).copy();
Expand Down

0 comments on commit 0284ca0

Please sign in to comment.