From: David Mason Date: Thu, 24 Mar 2016 17:48:51 +0000 (-0700) Subject: Fix spurious warning about parameter counts X-Git-Tag: accepted/tizen/base/20180629.140029~5200^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b45dbec2efcdc9713ddf50d57d8df3564874b345;p=platform%2Fupstream%2Fcoreclr.git Fix spurious warning about parameter counts --- diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs b/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs index be72b54..218826a 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs @@ -2117,12 +2117,34 @@ namespace System.Diagnostics.Tracing #endif //!ES_BUILD_PCL } + private int GetParamLenghtIncludingByteArray(ParameterInfo[] parameters) + { + int sum = 0; + foreach(ParameterInfo info in parameters) + { + if(info.ParameterType == typeof(byte[])) + { + sum += 2; + } + else + { + sum++; + } + } + + return sum; + } + [SecurityCritical] unsafe private void WriteToAllListeners(int eventId, Guid* childActivityID, int eventDataCount, EventSource.EventData* data) { - int paramCount = GetParameterCount(m_eventData[eventId]); - - if (eventDataCount != paramCount) + // We represent a byte[] as a integer denoting the length and then a blob of bytes in the data pointer. This causes a spurious + // warning because eventDataCount is off by one for the byte[] case since a byte[] has 2 items associated it. So we want to check + // that the number of parameters is correct against the byte[] case, but also we the args array would be one too long if + // we just used the modifiedParamCount here -- so we need both. + int paramCount = m_eventData[eventId].Parameters.Length; + int modifiedParamCount = GetParamLenghtIncludingByteArray(m_eventData[eventId].Parameters); + if (eventDataCount != modifiedParamCount) { ReportOutOfBandMessage(Resources.GetResourceString("EventSource_EventParametersMismatch", eventId, eventDataCount, paramCount), true); paramCount = Math.Min(paramCount, eventDataCount);