From 3fe982232b0fa320db6932ff049eaeb0d2685a6a Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 14 Apr 2013 10:50:22 -0400 Subject: [PATCH] Fix array typecasting. Since a C/C++ array is essentially pointer math, the derived type needs to take this into account, otherwise the array indices wind up being based off the address of the variable itself rather than the array it points to. --- src/apps/debugger/source_language/CppLanguage.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/apps/debugger/source_language/CppLanguage.cpp b/src/apps/debugger/source_language/CppLanguage.cpp index d1904648dc..edecb08e5f 100644 --- a/src/apps/debugger/source_language/CppLanguage.cpp +++ b/src/apps/debugger/source_language/CppLanguage.cpp @@ -111,7 +111,6 @@ CppLanguage::ParseTypeExpression(const BString &expression, _resultType = baseType; -#if 0 if (!arraySpecifier.IsEmpty()) { ArrayType* arrayType = NULL; @@ -139,9 +138,18 @@ CppLanguage::ParseTypeExpression(const BString &expression, } while (startIndex >= 0); - _resultType = arrayType; + // since a C/C++ array is essentially pointer math, + // the resulting array has to be wrapped in a pointer to + // ensure the element addresses wind up being against the + // correct address. + AddressType* addressType = NULL; + result = arrayType->CreateDerivedAddressType(DERIVED_TYPE_POINTER, + addressType); + if (result != B_OK) + return result; + + _resultType = addressType; } -#endif typeRef.Detach();