From 92880ea6814ac1d30a6f058f94a7fe0069c50e36 Mon Sep 17 00:00:00 2001 From: kai Date: Thu, 31 Oct 2013 12:14:11 +0100 Subject: [PATCH] Correct issues found by AddressSanitizer. The changes in this pull request fixes issues found by AddressSanitizer from LLVM 3.4. --- src/identifier.c | 10 +++++----- src/mangle.c | 2 +- src/root/rmem.c | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/identifier.c b/src/identifier.c index a6e959143ecc..863a99e12226 100644 --- a/src/identifier.c +++ b/src/identifier.c @@ -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() @@ -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"; } } diff --git a/src/mangle.c b/src/mangle.c index 17776064df65..513ce82be931 100644 --- a/src/mangle.c +++ b/src/mangle.c @@ -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); diff --git a/src/root/rmem.c b/src/root/rmem.c index 9af974822e98..a0fc20fa1214 100644 --- a/src/root/rmem.c +++ b/src/root/rmem.c @@ -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 @@ -187,3 +195,5 @@ void operator delete(void *p) } #endif + +#endif