Replace reinterpret_cast with safer or no cast
When casting types to one another in C++, the weaker the cast,
the better.
This change replaces instances of reinterpret_cast with static_cast
or no cast where it safe and correct to do so.
BUG=angleproject:2683
Change-Id: I99c9033614a65282ae1d78cf0f4b80fabd75877a
Reviewed-on: https://chromium-review.googlesource.com/1109396
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/Common.h b/src/compiler/translator/Common.h
index b606e85..f2dfc6a 100644
--- a/src/compiler/translator/Common.h
+++ b/src/compiler/translator/Common.h
@@ -121,7 +121,7 @@
inline const char *AllocatePoolCharArray(const char *str, size_t strLength)
{
size_t requiredSize = strLength + 1;
- char *buffer = reinterpret_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
+ char *buffer = static_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
memcpy(buffer, str, requiredSize);
ASSERT(buffer[strLength] == '\0');
return buffer;
diff --git a/src/compiler/translator/ImmutableStringBuilder.h b/src/compiler/translator/ImmutableStringBuilder.h
index 09fcc71..f7ed515 100644
--- a/src/compiler/translator/ImmutableStringBuilder.h
+++ b/src/compiler/translator/ImmutableStringBuilder.h
@@ -58,7 +58,7 @@
inline static char *AllocateEmptyPoolCharArray(size_t strLength)
{
size_t requiredSize = strLength + 1u;
- return reinterpret_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
+ return static_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
}
size_t mPos;
diff --git a/src/compiler/translator/PoolAlloc.h b/src/compiler/translator/PoolAlloc.h
index ad63bc4..5373264 100644
--- a/src/compiler/translator/PoolAlloc.h
+++ b/src/compiler/translator/PoolAlloc.h
@@ -295,11 +295,11 @@
#else
pointer allocate(size_type n)
{
- return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T)));
+ return static_cast<pointer>(getAllocator().allocate(n * sizeof(T)));
}
pointer allocate(size_type n, const void *)
{
- return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T)));
+ return static_cast<pointer>(getAllocator().allocate(n * sizeof(T)));
}
void deallocate(pointer, size_type) {}
#endif // _RWSTD_ALLOCATOR
diff --git a/src/compiler/translator/ShaderLang.cpp b/src/compiler/translator/ShaderLang.cpp
index e1f814b..d8aff5f 100644
--- a/src/compiler/translator/ShaderLang.cpp
+++ b/src/compiler/translator/ShaderLang.cpp
@@ -313,7 +313,7 @@
return 0;
}
- return reinterpret_cast<void *>(base);
+ return base;
}
void Destruct(ShHandle handle)
diff --git a/src/compiler/translator/tree_util/IntermNode_util.cpp b/src/compiler/translator/tree_util/IntermNode_util.cpp
index cb3029d..d5c822a 100644
--- a/src/compiler/translator/tree_util/IntermNode_util.cpp
+++ b/src/compiler/translator/tree_util/IntermNode_util.cpp
@@ -236,7 +236,7 @@
TIntermSymbol *ReferenceGlobalVariable(const ImmutableString &name, const TSymbolTable &symbolTable)
{
- const TVariable *var = reinterpret_cast<const TVariable *>(symbolTable.findGlobal(name));
+ const TVariable *var = static_cast<const TVariable *>(symbolTable.findGlobal(name));
ASSERT(var);
return new TIntermSymbol(var);
}
@@ -246,7 +246,7 @@
int shaderVersion)
{
const TVariable *var =
- reinterpret_cast<const TVariable *>(symbolTable.findBuiltIn(name, shaderVersion));
+ static_cast<const TVariable *>(symbolTable.findBuiltIn(name, shaderVersion));
ASSERT(var);
return new TIntermSymbol(var);
}