Skip to content

Commit

Permalink
Merge pull request #2699 from redstar/asan
Browse files Browse the repository at this point in the history
Correct issues found by AddressSanitizer.
  • Loading branch information
yebblies committed Mar 5, 2014
2 parents a312476 + 92880ea commit c50f0bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/identifier.c
Expand Up @@ -32,12 +32,12 @@ Identifier *Identifier::create(const char *string, int value)

bool Identifier::equals(RootObject *o)
{
return this == o || memcmp(string,o->toChars(),len+1) == 0;
return this == o || strncmp(string,o->toChars(),len+1) == 0;
}

int Identifier::compare(RootObject *o)
{
return memcmp(string, o->toChars(), len + 1);
return strncmp(string, o->toChars(), len + 1);
}

char *Identifier::toChars()
Expand All @@ -60,11 +60,11 @@ const char *Identifier::toHChars2()
{ p = toChars();
if (*p == '_')
{
if (memcmp(p, "_staticCtor", 11) == 0)
if (strncmp(p, "_staticCtor", 11) == 0)
p = "static this";
else if (memcmp(p, "_staticDtor", 11) == 0)
else if (strncmp(p, "_staticDtor", 11) == 0)
p = "static ~this";
else if (memcmp(p, "__invariant", 11) == 0)
else if (strncmp(p, "__invariant", 11) == 0)
p = "invariant";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mangle.c
Expand Up @@ -332,7 +332,7 @@ class Mangler : public Visitor
cd == ClassDeclaration::object ||
cd == Type::typeinfoclass ||
cd == Module::moduleinfo ||
memcmp(cd->ident->toChars(), "TypeInfo_", 9) == 0)
strncmp(cd->ident->toChars(), "TypeInfo_", 9) == 0)
cd->parent = NULL;

visit((AggregateDeclaration *)cd);
Expand Down
10 changes: 10 additions & 0 deletions src/root/rmem.c
Expand Up @@ -116,6 +116,14 @@ void Mem::error()

/* =================================================== */

#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define USE_ASAN_NEW_DELETE
#endif
#endif

#if !defined(USE_ASAN_NEW_DELETE)

#if 1

/* Allocate, but never release
Expand Down Expand Up @@ -187,3 +195,5 @@ void operator delete(void *p)
}

#endif

#endif

0 comments on commit c50f0bb

Please sign in to comment.