diff --git a/src/Agent/NewRelic/Home/Home.csproj b/src/Agent/NewRelic/Home/Home.csproj index 2826f4cffe..11f2614b9b 100644 --- a/src/Agent/NewRelic/Home/Home.csproj +++ b/src/Agent/NewRelic/Home/Home.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Agent/NewRelic/Profiler/Common/CorStandIn.h b/src/Agent/NewRelic/Profiler/Common/CorStandIn.h index 0cfc09a524..ae80eab51a 100644 --- a/src/Agent/NewRelic/Profiler/Common/CorStandIn.h +++ b/src/Agent/NewRelic/Profiler/Common/CorStandIn.h @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ #pragma warning(push) -#pragma warning(disable : 4458) +// Since this isn't our code, we don't want to mess with it. These warnings can be safely ignored. +#pragma warning(disable: 4458) // Scope hides class member with same name. +#pragma warning(disable: 26495) // Uninitialized member variable, even if it's always set before use. #include #pragma warning(pop) diff --git a/src/Agent/NewRelic/Profiler/Configuration/Configuration.h b/src/Agent/NewRelic/Profiler/Configuration/Configuration.h index 14e816327a..8fbe4a3677 100644 --- a/src/Agent/NewRelic/Profiler/Configuration/Configuration.h +++ b/src/Agent/NewRelic/Profiler/Configuration/Configuration.h @@ -47,10 +47,10 @@ namespace NewRelic { namespace Profiler { namespace Configuration { , _ignoreList(new IgnoreInstrumentationList()) { try { - rapidxml::xml_document globalNewRelicConfigurationDocument; - globalNewRelicConfigurationDocument.parse(const_cast(globalNewRelicConfiguration.c_str())); + auto globalNewRelicConfigurationDocument = std::make_shared>(); + globalNewRelicConfigurationDocument->parse(const_cast(globalNewRelicConfiguration.c_str())); - auto globalNewRelicConfigurationNode = GetConfigurationNode(globalNewRelicConfigurationDocument); + auto globalNewRelicConfigurationNode = GetConfigurationNode(globalNewRelicConfigurationDocument); if (globalNewRelicConfigurationNode == nullptr) { LogError(L"Unable to locate configuration node in the global newrelic.config file."); @@ -58,13 +58,13 @@ namespace NewRelic { namespace Profiler { namespace Configuration { } auto appliedNewRelicConfigurationNode = globalNewRelicConfigurationNode; + auto localNewRelicConfigurationDocument = std::make_shared>(); if (localNewRelicConfiguration.second) { try { - rapidxml::xml_document localNewRelicConfigurationDocument; - localNewRelicConfigurationDocument.parse(const_cast(localNewRelicConfiguration.first.c_str())); + localNewRelicConfigurationDocument->parse(const_cast(localNewRelicConfiguration.first.c_str())); auto localNewRelicConfigurationNode = GetConfigurationNode(localNewRelicConfigurationDocument); if (localNewRelicConfigurationNode == nullptr) @@ -92,7 +92,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration { SetLogLevel(appliedNewRelicConfigurationNode); SetInstrumentationData(appliedNewRelicConfigurationNode); SetApplicationPools(appliedNewRelicConfigurationNode); - + } catch (const rapidxml::parse_error& exception) { // We log two separate error messages here because sometimes the logging macros hang when // logging the "where" contents @@ -196,15 +196,15 @@ namespace NewRelic { namespace Profiler { namespace Configuration { return _logLevel; } - bool GetConsoleLogging() + bool GetConsoleLogging() const { return _consoleLogging; } - bool GetLoggingEnabled() + bool GetLoggingEnabled() const { return _loggingEnabled; } - IgnoreInstrumentationListPtr GetIgnoreInstrumentationList() + IgnoreInstrumentationListPtr GetIgnoreInstrumentationList() const { return _ignoreList; } @@ -224,9 +224,9 @@ namespace NewRelic { namespace Profiler { namespace Configuration { std::shared_ptr _systemCalls; IgnoreInstrumentationListPtr _ignoreList; - rapidxml::xml_node* GetConfigurationNode(const rapidxml::xml_document& document) + rapidxml::xml_node* GetConfigurationNode(const std::shared_ptr> document) { - auto configurationNode = document.first_node(_X("configuration"), 0, false); + auto configurationNode = document->first_node(_X("configuration"), 0, false); if (configurationNode == nullptr) { return nullptr; } @@ -294,7 +294,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration { _logLevel = TryParseLogLevel(level); } - Logger::Level TryParseLogLevel(const xstring_t& logText) + Logger::Level TryParseLogLevel(const xstring_t& logText) const { if (Strings::AreEqualCaseInsensitive(logText, _X("off"))) { return Logger::Level::LEVEL_ERROR; @@ -423,8 +423,8 @@ namespace NewRelic { namespace Profiler { namespace Configuration { if (applicationConfiguration.empty()) return; - rapidxml::xml_document document; - document.parse(const_cast(applicationConfiguration.c_str())); + auto document = std::make_shared>(); + document->parse(const_cast(applicationConfiguration.c_str())); auto configurationNode = GetConfigurationNode(document); auto appSettingsNode = configurationNode->first_node(_X("appSettings"), 0, false); @@ -468,7 +468,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration { static bool IsProcessInProcessList(const ProcessesPtr& processes, const xstring_t& processName) { // check the processes loaded from configuration - for (auto validProcessName : *processes) { + for (auto& validProcessName : *processes) { if (Strings::EndsWith(processName, validProcessName)) { return true; } @@ -498,7 +498,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration { return isIis; } - bool ShouldInstrumentApplicationPool(const xstring_t& appPoolId) + bool ShouldInstrumentApplicationPool(const xstring_t& appPoolId) const { if (ApplicationPoolIsOnBlackList(appPoolId, _applicationPoolsBlackList)) { LogInfo(_X("This application pool (") + appPoolId + _X(") is explicitly configured to NOT be instrumented.")); diff --git a/src/Agent/NewRelic/Profiler/Configuration/IgnoreInstrumentation.h b/src/Agent/NewRelic/Profiler/Configuration/IgnoreInstrumentation.h index 98438898bf..a98f68e09b 100644 --- a/src/Agent/NewRelic/Profiler/Configuration/IgnoreInstrumentation.h +++ b/src/Agent/NewRelic/Profiler/Configuration/IgnoreInstrumentation.h @@ -50,7 +50,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration } private: - bool Matches(xstring_t assembly, xstring_t className) + bool Matches(xstring_t assembly, xstring_t className) const { if (!Strings::AreEqualCaseInsensitive(AssemblyName, assembly)) { diff --git a/src/Agent/NewRelic/Profiler/Configuration/InstrumentationConfiguration.h b/src/Agent/NewRelic/Profiler/Configuration/InstrumentationConfiguration.h index 649d4083b4..eee0f162ab 100644 --- a/src/Agent/NewRelic/Profiler/Configuration/InstrumentationConfiguration.h +++ b/src/Agent/NewRelic/Profiler/Configuration/InstrumentationConfiguration.h @@ -33,7 +33,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration , _foundServerlessInstrumentationPoint(false) { // pull instrumentation points from every xml string - for (auto instrumentationXml : *instrumentationXmls) + for (auto& instrumentationXml : *instrumentationXmls) { try { @@ -64,13 +64,13 @@ namespace NewRelic { namespace Profiler { namespace Configuration , _systemCalls(nullptr) , _foundServerlessInstrumentationPoint(false) { - for (auto instrumentationPoint : *instrumentationPoints) + for (auto& instrumentationPoint : *instrumentationPoints) { AddInstrumentationPointToCollectionsIfNotIgnored(instrumentationPoint); } } - uint16_t GetInvalidFileCount() + uint16_t GetInvalidFileCount() const { return _invalidFileCount; } @@ -100,7 +100,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration // We may have multiple matching instrumentation points that target different assembly versions. See if we can find one that meets // the version requirements AssemblyVersion foundVersion(function->GetAssemblyProps()); - for (auto instPoint : instPoints) + for (auto& instPoint : instPoints) { if ((instPoint->MinVersion != nullptr) && (foundVersion < *instPoint->MinVersion)) { @@ -228,9 +228,9 @@ namespace NewRelic { namespace Profiler { namespace Configuration void GetInstrumentationPoints(xstring_t instrumentationXml) { - rapidxml::xml_document document; - document.parse(const_cast(instrumentationXml.c_str())); - auto extensionNode = document.first_node(_X("extension"), 0, false); + auto document = std::make_shared>(); + document->parse(const_cast(instrumentationXml.c_str())); + auto extensionNode = document->first_node(_X("extension"), 0, false); if (extensionNode == nullptr) { LogWarn(L"extension node not found in instrumentation file. Please validate your instrumentation files against extensions/extension.xsd or contact New Relic support."); @@ -397,7 +397,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration // if the ClassName includes multiple classes, we have to split this into multiple instrumentation points auto instrumentationPoints = SplitInstrumentationPointsOnClassNames(instrumentationPoint); - for (auto iPoint : instrumentationPoints) { + for (auto& iPoint : instrumentationPoints) { // finally add the new instrumentation point(s) to our set of instrumentation points // Note that there may be "duplicated" instrumentation points that target different assembly versions diff --git a/src/Agent/NewRelic/Profiler/Configuration/InstrumentationPoint.h b/src/Agent/NewRelic/Profiler/Configuration/InstrumentationPoint.h index 17363d4938..7a08d71e06 100644 --- a/src/Agent/NewRelic/Profiler/Configuration/InstrumentationPoint.h +++ b/src/Agent/NewRelic/Profiler/Configuration/InstrumentationPoint.h @@ -52,7 +52,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration ParametersMatch(other); } - xstring_t ToString() + xstring_t ToString() const { if (Parameters == nullptr) { @@ -63,7 +63,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration } } - xstring_t GetMatchKey() + xstring_t GetMatchKey() const { return Parameters == nullptr ? GetMatchKey(AssemblyName, ClassName, MethodName) @@ -82,7 +82,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration private: - bool ParametersMatch(const InstrumentationPoint& other) + bool ParametersMatch(const InstrumentationPoint& other) const { // nullptr means no parameters attribute was supplied in configuration, suggesting that we should instrument all overloads if (this->Parameters == nullptr) diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/ExceptionHandlerManipulator.h b/src/Agent/NewRelic/Profiler/MethodRewriter/ExceptionHandlerManipulator.h index ce5ef9f520..f955ad9eee 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/ExceptionHandlerManipulator.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/ExceptionHandlerManipulator.h @@ -262,12 +262,12 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter // shift the original clauses up to the correct for (uint32_t i = 0; i < _originalExceptionClauseCount; ++i) { - auto clause = _exceptionClauses[i]; + auto& clause = _exceptionClauses[i]; clause->ShiftOffsets(userCodeOffset); } // append the clauses - for (auto clause : _exceptionClauses) + for (auto& clause : _exceptionClauses) { auto clauseBytes = clause->GetBytes(); bytes->insert(bytes->end(), clauseBytes->begin(), clauseBytes->end()); @@ -276,7 +276,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter return bytes; } - uint32_t GetOriginalExceptionClauseCount() + uint32_t GetOriginalExceptionClauseCount() const { return _originalExceptionClauseCount; } diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/FunctionManipulator.h b/src/Agent/NewRelic/Profiler/MethodRewriter/FunctionManipulator.h index 56bbaf3683..81bfbccfd8 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/FunctionManipulator.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/FunctionManipulator.h @@ -350,7 +350,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter _instructions->Append(CEE_NEWARR, _X("[mscorlib]System.Object")); uint32_t index = 0; - for (auto func : elementLoadLambdas) + for (auto& func : elementLoadLambdas) { auto nextIndex = index++; // get an extra copy of the array (it will be popped off the stack each time we add an element to it) diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/InstructionSet.h b/src/Agent/NewRelic/Profiler/MethodRewriter/InstructionSet.h index 0b4493dd2d..77592897b9 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/InstructionSet.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/InstructionSet.h @@ -403,7 +403,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter void AppendTryEnd() { - auto exception = _exceptionStack.top(); + auto& exception = _exceptionStack.top(); if (exception->_tryLength != 0) { LogError(L"Attempted to set try close on the same exception twice."); @@ -414,7 +414,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter void AppendCatchStart(uint32_t typeToken) { - auto exception = _exceptionStack.top(); + auto& exception = _exceptionStack.top(); if (exception->_handlerOffset != 0) { LogError(L"Attempted to set catch start on the same exception twice."); @@ -439,7 +439,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter void AppendCatchEnd() { - auto exception = _exceptionStack.top(); + auto& exception = _exceptionStack.top(); if (exception->_handlerLength != 0) { LogError(L"Attempted to set catch end on the same exception twice."); diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h b/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h index 1a11be8a7e..5e90471b93 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/InstrumentFunctionManipulator.h @@ -16,7 +16,10 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter public: InstrumentFunctionManipulator(IFunctionPtr function, InstrumentationSettingsPtr instrumentationSettings) : FunctionManipulator(function), - _instrumentationSettings(instrumentationSettings) + _instrumentationSettings(instrumentationSettings), + _userExceptionLocalIndex(0), + _resultLocalIndex(0), + _tracerLocalIndex(0) { if (_function->Preprocess()) { Initialize(); @@ -228,4 +231,4 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter _resultLocalIndex = AppendReturnTypeLocal(_newLocalVariablesSignature, _methodSignature); } }; -}}} \ No newline at end of file +}}} diff --git a/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h b/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h index 3dd98229d7..1f05a83204 100644 --- a/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h +++ b/src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h @@ -54,7 +54,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { auto instrumentationPoints = _instrumentationConfiguration->GetInstrumentationPoints(); - for (auto instrumentationPoint : *instrumentationPoints) { + for (auto& instrumentationPoint : *instrumentationPoints) { _instrumentedAssemblies->emplace(instrumentationPoint->AssemblyName); _instrumentedFunctionNames->emplace(instrumentationPoint->MethodName); @@ -74,7 +74,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter { std::set GetAssemblyInstrumentation(xstring_t assemblyName) { std::set set; - for (auto instrumentationPoint : *_instrumentationConfiguration->GetInstrumentationPoints().get()) { + for (auto& instrumentationPoint : *_instrumentationConfiguration->GetInstrumentationPoints().get()) { if (assemblyName == instrumentationPoint->AssemblyName) { set.emplace(instrumentationPoint); } diff --git a/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h b/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h index 5217285b75..3fa8619ae9 100644 --- a/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h +++ b/src/Agent/NewRelic/Profiler/ModuleInjector/ModuleInjector.h @@ -10,6 +10,7 @@ #include "../Logging/Logger.h" #include "../Sicily/Sicily.h" #include "IModule.h" +#include "../Profiler/Exceptions.h" namespace NewRelic { namespace Profiler { namespace ModuleInjector { diff --git a/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h b/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h index aeaf684641..268b107e71 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h +++ b/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h @@ -574,7 +574,7 @@ namespace NewRelic { namespace Profiler { std::shared_ptr> GroupByAssemblyName(Configuration::InstrumentationPointSetPtr allInstrumentationPoints) { std::shared_ptr> instrumentationPointsByAssembly = std::make_shared>(); - for (auto point : *allInstrumentationPoints) { + for (auto& point : *allInstrumentationPoints) { Configuration::InstrumentationPointSetPtr instrumentationPoints; auto it = instrumentationPointsByAssembly->find(point->AssemblyName); @@ -632,7 +632,7 @@ namespace NewRelic { namespace Profiler { auto instrumentationXmls = GetInstrumentationXmlsFromDisk(_systemCalls); auto customXml = _customInstrumentation.GetCustomInstrumentationXml(); - for (auto xmlPair : *customXml) { + for (auto& xmlPair : *customXml) { (*instrumentationXmls)[xmlPair.first] = xmlPair.second; } @@ -683,7 +683,7 @@ namespace NewRelic { namespace Profiler { { auto oldIter = instrumentationByAssembly->find(assemblyName); if (oldIter != instrumentationByAssembly->end()) { - auto points = oldIter->second; + auto& points = oldIter->second; return GetMethodDefs(moduleId, points); } @@ -789,12 +789,15 @@ namespace NewRelic { namespace Profiler { ModuleID* moduleIds = new ModuleID[numberMethods]; mdMethodDef* methodIds = new mdMethodDef[numberMethods]; +#pragma warning(push) +#pragma warning(disable : 6386) // Not possible to overrun the buffer since we're using the set size int i = 0; for (auto methodDef : *methodSet) { moduleIds[i] = moduleId; methodIds[i] = methodDef; i++; } +#pragma warning(pop) func(numberMethods, moduleIds, methodIds); @@ -879,7 +882,7 @@ namespace NewRelic { namespace Profiler { bool _isCoreClr = false; - MethodRewriter::MethodRewriterPtr GetMethodRewriter() + MethodRewriter::MethodRewriterPtr GetMethodRewriter() const { return std::atomic_load(&_methodRewriter); } @@ -942,7 +945,7 @@ namespace NewRelic { namespace Profiler { auto filePaths = GetXmlFilesInExtensionsDirectory(systemCalls); - for (auto filePath : filePaths) { + for (auto& filePath : filePaths) { instrumentationXmls->emplace(filePath, ReadFile(filePath)); } @@ -1258,7 +1261,7 @@ namespace NewRelic { namespace Profiler { struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; - } * lpTranslate; + } *lpTranslate = nullptr; //xstring_t expectedProductName = _X("New Relic .NET CoreCLR Agent"); @@ -1277,7 +1280,7 @@ namespace NewRelic { namespace Profiler { if (VerQueryValue(versionInfo, (LPTSTR)szSFI, (LPVOID*)&lpszBuf, &uLen)) { if (expectedProductName == lpszBuf) { - void* block; + void* block = nullptr; UINT blockSize; if (VerQueryValue(versionInfo, L"\\", (LPVOID*)&block, &blockSize)) { auto fileInfo = (VS_FIXEDFILEINFO*)block; diff --git a/src/Agent/NewRelic/Profiler/Profiler/CorTokenResolver.h b/src/Agent/NewRelic/Profiler/Profiler/CorTokenResolver.h index 10d7d719d5..b3db943938 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/CorTokenResolver.h +++ b/src/Agent/NewRelic/Profiler/Profiler/CorTokenResolver.h @@ -42,7 +42,7 @@ namespace NewRelic { namespace Profiler xstring_t GetTypeStringsFromTypeSpec(uint32_t typeDefOrRefOrSpecToken) { - uint8_t* signature; + uint8_t* signature = 0; ULONG signatureLength; _metaDataImport->GetTypeSpecFromToken(typeDefOrRefOrSpecToken, (PCCOR_SIGNATURE*)(&signature), &signatureLength); diff --git a/src/Agent/NewRelic/Profiler/Profiler/CorTokenizer.h b/src/Agent/NewRelic/Profiler/Profiler/CorTokenizer.h index 9b43baa352..f1487fcc90 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/CorTokenizer.h +++ b/src/Agent/NewRelic/Profiler/Profiler/CorTokenizer.h @@ -304,7 +304,7 @@ namespace NewRelic { namespace Profiler xstring_t ResolveAssemblyForType(xstring_t assemblyName, xstring_t fullQualifiedType) { - auto coreAssembly = (*_typeNameToAssembly.get())[fullQualifiedType]; + auto& coreAssembly = (*_typeNameToAssembly.get())[fullQualifiedType]; return coreAssembly.empty() ? assemblyName : coreAssembly; } }; diff --git a/src/Agent/NewRelic/Profiler/Profiler/Function.h b/src/Agent/NewRelic/Profiler/Profiler/Function.h index fc586e8eeb..c9f8738144 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/Function.h +++ b/src/Agent/NewRelic/Profiler/Profiler/Function.h @@ -431,7 +431,7 @@ namespace NewRelic { namespace Profiler return _functionId; } - ModuleID GetModuleID() + ModuleID GetModuleID() const { return _moduleId; } @@ -536,7 +536,7 @@ namespace NewRelic { namespace Profiler virtual ByteVectorPtr GetSignatureFromToken(mdToken token) override { ULONG signatureLength; - uint8_t* signature; + uint8_t* signature = 0; ThrowOnError(_metaDataImport->GetSigFromToken, token, (PCCOR_SIGNATURE*)&signature, &signatureLength); return std::make_shared(signature, signature + signatureLength); } diff --git a/src/Agent/NewRelic/Profiler/Profiler/FunctionHeaderInfo.h b/src/Agent/NewRelic/Profiler/Profiler/FunctionHeaderInfo.h index 053a53afde..eeed2436fb 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/FunctionHeaderInfo.h +++ b/src/Agent/NewRelic/Profiler/Profiler/FunctionHeaderInfo.h @@ -68,7 +68,7 @@ namespace NewRelic { else if (info->instruction == CEE_SWITCH) { counts.switchCount += 1; const unsigned numberArms = ReadNumber(&bodyBytes[pos + 1], 4) & 0xFFFFFFFF; - const unsigned numberBytesTable = (1 + numberArms) * sizeof(DWORD); + const unsigned numberBytesTable = (1 + static_cast(numberArms)) * sizeof(DWORD); const unsigned totalBytesInstruction = 1 + numberBytesTable; pos += totalBytesInstruction; } @@ -209,4 +209,4 @@ namespace NewRelic { } } } -} \ No newline at end of file +} diff --git a/src/Agent/NewRelic/Profiler/Profiler/FunctionPreprocessor.h b/src/Agent/NewRelic/Profiler/Profiler/FunctionPreprocessor.h index da9f78c57c..a5bc8db7e1 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/FunctionPreprocessor.h +++ b/src/Agent/NewRelic/Profiler/Profiler/FunctionPreprocessor.h @@ -140,15 +140,15 @@ namespace NewRelic { } } - OpCodePtr GetOpCode() + OpCodePtr GetOpCode() const { return _opcode; } - unsigned GetOffset() + unsigned GetOffset() const { return _offset; } - bool IsValid() + bool IsValid() const { return _valid; } @@ -177,7 +177,7 @@ namespace NewRelic { { auto offsetOfInstructionFollowingSwitch = _offset + _opcode->totalSize; auto offsetOfArm = _offset + _opcode->instructionSize + sizeof(DWORD); - for (auto target : *_targets) { + for (auto& target : *_targets) { auto jumpLength = target->GetOffset() - offsetOfInstructionFollowingSwitch; auto armLocation = instructions->data() + offsetOfArm; @@ -193,7 +193,7 @@ namespace NewRelic { { // a better person would do this in place but the iter pointer stuff confuses me auto newTargetsList = std::make_shared>(); - for (auto targetInstruction : *_targets) { + for (auto& targetInstruction : *_targets) { if (oldInstruction == targetInstruction) { newTargetsList->push_back(newInstruction); @@ -232,11 +232,14 @@ namespace NewRelic { class BranchInstruction :public Instruction { public: - BranchInstruction(OpCodePtr opCode, unsigned offset) : Instruction(opCode, offset) + BranchInstruction(OpCodePtr opCode, unsigned offset) : Instruction(opCode, offset), + _targetInstruction(nullptr), + _targetOffset(0) { } - BranchInstruction(OpCodePtr opCode, unsigned offset, InstructionPtr target) : Instruction(opCode, offset) + BranchInstruction(OpCodePtr opCode, unsigned offset, InstructionPtr target) : Instruction(opCode, offset), + _targetOffset(0) { _targetInstruction = target; } @@ -384,7 +387,7 @@ namespace NewRelic { } // sanity check the final instruction. If it isn't a RET, we likely mucked up the instruction parsing - auto lastInstruction = instructions->at(finalInstructionIndex); + auto& lastInstruction = instructions->at(finalInstructionIndex); if (lastInstruction->GetOpCode()->instruction != CEE_RET) { LogTrace(L"Expected RET as final instruction but found ", lastInstruction->GetOpCode()->instruction); return nullptr; @@ -396,7 +399,7 @@ namespace NewRelic { lastInstruction->GetOpCode()->Reset(GetOpCode(CEE_NOP)); auto branches = std::make_shared>(); - for (auto instruction : *instructions.get()) + for (auto& instruction : *instructions.get()) { if (instruction.second->GetOpCode()->instruction == CEE_RET) { @@ -432,14 +435,14 @@ namespace NewRelic { // write the instructions into our bytecode vector. that'll reset the offsets // of the instructions so that we can recompute the branch jumps. - for (auto instruction : *instructions.get()) + for (auto& instruction : *instructions.get()) { instruction.second->Write(oldCodeBytes, newByteCode); } // now all instructions contain their final offset, so we can // write the branch instruction offsets - for (auto branch : *branches) { + for (auto& branch : *branches) { branch->WriteBranches(newByteCode, instructions); } @@ -481,7 +484,7 @@ namespace NewRelic { static void NotifyOfInstructionChange(OffsetToInstructionMapPtr instructions, InstructionPtr oldInstruction, InstructionPtr newInstruction) { - for (auto iter : *instructions) + for (auto& iter : *instructions) { iter.second->OnInstructionChange(oldInstruction, newInstruction); } @@ -489,7 +492,7 @@ namespace NewRelic { static bool AllValid(OffsetToInstructionMapPtr instructions) { - for (auto instruction : *instructions.get()) + for (auto& instruction : *instructions.get()) { if (!instruction.second->IsValid()) { return false; @@ -527,7 +530,7 @@ namespace NewRelic { static void PrintInstructions(OffsetToInstructionMapPtr instructions) { #ifdef DEBUG - for (auto iter : *instructions.get()) + for (auto& iter : *instructions.get()) { LogInfo(iter.second->ToString()); } @@ -603,23 +606,23 @@ namespace NewRelic { for (unsigned c = 0; c < sehClauseCount; c++) { COR_ILMETHOD_SECT_EH_CLAUSE_FAT* clause = &sehClauses[c]; - auto tryInstruction = instructions->at(clause->TryOffset); + auto& tryInstruction = instructions->at(clause->TryOffset); //unsigned newTryLength = _oldPositionToNew[clause->TryOffset + clause->TryLength] - _oldPositionToNew[clause->TryOffset]; - auto tryEndInstruction = instructions->at(clause->TryOffset + clause->TryLength); + auto& tryEndInstruction = instructions->at(clause->TryOffset + clause->TryLength); auto tryLength = tryEndInstruction->GetOffset() - tryInstruction->GetOffset(); clause->SetTryLength(tryLength); clause->SetTryOffset(tryInstruction->GetOffset()); - auto handlerInstruction = instructions->at(clause->HandlerOffset); - auto handlerEndInstruction = instructions->at(clause->HandlerOffset + clause->HandlerLength); + auto& handlerInstruction = instructions->at(clause->HandlerOffset); + auto& handlerEndInstruction = instructions->at(clause->HandlerOffset + clause->HandlerLength); auto handlerLength = handlerEndInstruction->GetOffset() - handlerInstruction->GetOffset(); clause->SetHandlerLength(handlerLength); clause->SetHandlerOffset(handlerInstruction->GetOffset()); if (clause->GetFlags() == static_cast(COR_ILEXCEPTION_CLAUSE_FILTER)) { - auto filterInstruction = instructions->at(clause->FilterOffset); + auto& filterInstruction = instructions->at(clause->FilterOffset); clause->SetFilterOffset(filterInstruction->GetOffset()); // There's no FilterLength to adjust. @@ -668,7 +671,7 @@ namespace NewRelic { } // resolve the target instruction(s) of all branches - for (auto instruction : *branches) + for (auto& instruction : *branches) { instruction->ResolveTargets(methodBody, instructions); } diff --git a/src/Agent/NewRelic/Profiler/Profiler/OpCodes.h b/src/Agent/NewRelic/Profiler/Profiler/OpCodes.h index f517e123be..b10a396f25 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/OpCodes.h +++ b/src/Agent/NewRelic/Profiler/Profiler/OpCodes.h @@ -96,6 +96,16 @@ namespace NewRelic { unsigned controlFlow; xstring_t name; + OpCode() : + instruction(0), + instructionSize(0), + arrayOffset(0), + operandSize(0), + totalSize(0), + controlFlow(0) + {} + + void Reset(std::shared_ptr newOpCode) { instruction = newOpCode->instruction; @@ -146,4 +156,4 @@ namespace NewRelic { return GetOpCode((const BYTE*)&opcode, 0); } } -} \ No newline at end of file +} diff --git a/src/Agent/NewRelic/Profiler/Profiler/SystemCalls.h b/src/Agent/NewRelic/Profiler/Profiler/SystemCalls.h index fde2daed3f..1b42439c68 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/SystemCalls.h +++ b/src/Agent/NewRelic/Profiler/Profiler/SystemCalls.h @@ -44,7 +44,7 @@ namespace NewRelic { namespace Profiler static std::unique_ptr TryGetRegistryStringValue(HKEY rootKey, const xstring_t& path, const xstring_t& valueName) { - DWORD valueSize; + DWORD valueSize = 0; CRegKey key; // open the key diff --git a/src/Agent/NewRelic/Profiler/Profiler/stdafx.h b/src/Agent/NewRelic/Profiler/Profiler/stdafx.h index 7f16e03b1e..654b5cccbf 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/stdafx.h +++ b/src/Agent/NewRelic/Profiler/Profiler/stdafx.h @@ -33,7 +33,10 @@ // Profiler Header Files: +#pragma warning(push) +#pragma warning(disable: 26495) // Uninitialized member variable, even if it's always set before use #include +#pragma warning(pop) // Windows Header Files: #ifndef _WIN32_WINNT diff --git a/src/Agent/NewRelic/Profiler/RapidXML/rapidxml.hpp b/src/Agent/NewRelic/Profiler/RapidXML/rapidxml.hpp index a63f265fb6..59cba658fe 100644 --- a/src/Agent/NewRelic/Profiler/RapidXML/rapidxml.hpp +++ b/src/Agent/NewRelic/Profiler/RapidXML/rapidxml.hpp @@ -658,6 +658,8 @@ namespace rapidxml : m_name(0) , m_value(0) , m_parent(0) + , m_name_size(0) + , m_value_size(0) { } @@ -807,7 +809,9 @@ namespace rapidxml //! Constructs an empty attribute with the specified type. //! Consider using memory_pool of appropriate xml_document if allocating attributes manually. - xml_attribute() + xml_attribute() : + m_prev_attribute(nullptr), + m_next_attribute(nullptr) { } @@ -902,6 +906,10 @@ namespace rapidxml : m_type(type) , m_first_node(0) , m_first_attribute(0) + , m_last_node(0) + , m_last_attribute(0) + , m_prev_sibling(0) + , m_next_sibling(0) { } diff --git a/src/Agent/NewRelic/Profiler/SignatureParser/Types.h b/src/Agent/NewRelic/Profiler/SignatureParser/Types.h index e5cf551622..b6b1f02df8 100644 --- a/src/Agent/NewRelic/Profiler/SignatureParser/Types.h +++ b/src/Agent/NewRelic/Profiler/SignatureParser/Types.h @@ -475,7 +475,7 @@ namespace NewRelic { namespace Profiler { namespace SignatureParser stream += _type->ToString(tokenResolver); stream.push_back('['); bool first = true; - for (auto genericArgumentType : *_genericArgumentTypes) + for (auto& genericArgumentType : *_genericArgumentTypes) { if (first) first = false; else stream.push_back(','); @@ -493,7 +493,7 @@ namespace NewRelic { namespace Profiler { namespace SignatureParser bytes->push_back(ELEMENT_TYPE_GENERICINST); bytes->insert(bytes->end(), typeBytes->begin(), typeBytes->end()); bytes->insert(bytes->end(), compressedArgCount->begin(), compressedArgCount->end()); - for (auto argumentType : *_genericArgumentTypes) + for (auto& argumentType : *_genericArgumentTypes) { auto argumentTypeBytes = argumentType->ToBytes(); bytes->insert(bytes->end(), argumentTypeBytes->begin(), argumentTypeBytes->end()); @@ -801,11 +801,11 @@ namespace NewRelic { namespace Profiler { namespace SignatureParser _genericParamCount(genericParamCount) {} - xstring_t ToString(ITokenResolverPtr tokenResolver) + xstring_t ToString(ITokenResolverPtr tokenResolver) const { auto stream = xstring_t(); bool firstParam = true; - for (auto parameter : *_parameters) + for (auto& parameter : *_parameters) { if (firstParam) firstParam = false; else stream.push_back(','); @@ -836,7 +836,7 @@ namespace NewRelic { namespace Profiler { namespace SignatureParser auto returnTypeBytes = _returnType->ToBytes(); bytes->insert(bytes->end(), returnTypeBytes->begin(), returnTypeBytes->end()); - for (auto parameter : *_parameters) + for (auto& parameter : *_parameters) { auto parameterBytes = parameter->ToBytes(); bytes->insert(bytes->end(), parameterBytes->begin(), parameterBytes->end());