You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Bernd Klaiber (JIRA)" <ji...@apache.org> on 2006/09/25 03:00:40 UTC

[jira] Created: (LOG4NET-95) Level.CompareTo() may result a wrong Value -> sorting of Levels does not work

Level.CompareTo() may result a wrong Value -> sorting of Levels does not work
-----------------------------------------------------------------------------

                 Key: LOG4NET-95
                 URL: http://issues.apache.org/jira/browse/LOG4NET-95
             Project: Log4net
          Issue Type: Bug
          Components: Core
    Affects Versions: 1.2.10
         Environment: VS2005 C#
            Reporter: Bernd Klaiber
            Priority: Minor


I want to show a sorted list of available Levels.
The sort routine uses Level.Compare(Level l, Level r).
The result might be wrong when comparing ALL to another Level, because there is an overflow when just subtracting the m_levelValue.

try to call the integer compare method:
Level.cs:
		public static int Compare(Level l, Level r)
		{
			...
                        //orig: return l.m_levelValue - r.m_levelValue;  -> bug when int overflow
			return l.m_levelValue.CompareTo(r.m_levelValue);
		}

hope this helps.

best regards, Bernd.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (LOG4NET-95) Level.CompareTo() may result a wrong Value -> sorting of Levels does not work

Posted by "Ron Grabowski (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/LOG4NET-95?page=comments#action_12437433 ] 
            
Ron Grabowski commented on LOG4NET-95:
--------------------------------------

The CompareTo fix seems ok. I suspect subtraction was a clever way to save some cpu cycles.

FYI, Mono uses < and > instead of subtraction:

 http://svn.myrealbox.com/viewcvs/*checkout*/trunk/mcs/class/corlib/System/Int32.cs

 int xv = (int) v;
 if (m_value == xv)
  return 0;
 if (m_value > xv)
  return 1;
 else
  return -1;

Another solution would be to add a comment to the Level constructor and throw an ArgumentException for level values less than zero. There are 10,000 positive numbers between 0 and the lowest built-in log4net Level.

Since we know the two items we're comparing are ints, I think the inlined if/if/else block might save some cycles over CompareTo.

> Level.CompareTo() may result a wrong Value -> sorting of Levels does not work
> -----------------------------------------------------------------------------
>
>                 Key: LOG4NET-95
>                 URL: http://issues.apache.org/jira/browse/LOG4NET-95
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.10
>         Environment: VS2005 C#
>            Reporter: Bernd Klaiber
>            Priority: Minor
>
> I want to show a sorted list of available Levels.
> The sort routine uses Level.Compare(Level l, Level r).
> The result might be wrong when comparing ALL to another Level, because there is an overflow when just subtracting the m_levelValue.
> try to call the integer compare method:
> Level.cs:
> 		public static int Compare(Level l, Level r)
> 		{
> 			...
>                         //orig: return l.m_levelValue - r.m_levelValue;  -> bug when int overflow
> 			return l.m_levelValue.CompareTo(r.m_levelValue);
> 		}
> hope this helps.
> best regards, Bernd.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (LOG4NET-95) Level.CompareTo() may result a wrong Value -> sorting of Levels does not work

Posted by "Ron Grabowski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/LOG4NET-95?page=all ]

Ron Grabowski resolved LOG4NET-95.
----------------------------------

    Resolution: Fixed

Fixed in 463328. Replaced subtraction operator with System.Int32's CompareTo to avoid possible overflow errors. All tests continue to pass.

> Level.CompareTo() may result a wrong Value -> sorting of Levels does not work
> -----------------------------------------------------------------------------
>
>                 Key: LOG4NET-95
>                 URL: http://issues.apache.org/jira/browse/LOG4NET-95
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.10
>         Environment: VS2005 C#
>            Reporter: Bernd Klaiber
>         Assigned To: Ron Grabowski
>            Priority: Minor
>
> I want to show a sorted list of available Levels.
> The sort routine uses Level.Compare(Level l, Level r).
> The result might be wrong when comparing ALL to another Level, because there is an overflow when just subtracting the m_levelValue.
> try to call the integer compare method:
> Level.cs:
> 		public static int Compare(Level l, Level r)
> 		{
> 			...
>                         //orig: return l.m_levelValue - r.m_levelValue;  -> bug when int overflow
> 			return l.m_levelValue.CompareTo(r.m_levelValue);
> 		}
> hope this helps.
> best regards, Bernd.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (LOG4NET-95) Level.CompareTo() may result a wrong Value -> sorting of Levels does not work

Posted by "Ron Grabowski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-95?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ron Grabowski updated LOG4NET-95:
---------------------------------

    Fix Version/s: 1.2.11

> Level.CompareTo() may result a wrong Value -> sorting of Levels does not work
> -----------------------------------------------------------------------------
>
>                 Key: LOG4NET-95
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-95
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.10
>         Environment: VS2005 C#
>            Reporter: Bernd Klaiber
>            Assignee: Ron Grabowski
>            Priority: Minor
>             Fix For: 1.2.11
>
>
> I want to show a sorted list of available Levels.
> The sort routine uses Level.Compare(Level l, Level r).
> The result might be wrong when comparing ALL to another Level, because there is an overflow when just subtracting the m_levelValue.
> try to call the integer compare method:
> Level.cs:
> 		public static int Compare(Level l, Level r)
> 		{
> 			...
>                         //orig: return l.m_levelValue - r.m_levelValue;  -> bug when int overflow
> 			return l.m_levelValue.CompareTo(r.m_levelValue);
> 		}
> hope this helps.
> best regards, Bernd.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (LOG4NET-95) Level.CompareTo() may result a wrong Value -> sorting of Levels does not work

Posted by "Ron Grabowski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/LOG4NET-95?page=all ]

Ron Grabowski reassigned LOG4NET-95:
------------------------------------

    Assignee: Ron Grabowski

> Level.CompareTo() may result a wrong Value -> sorting of Levels does not work
> -----------------------------------------------------------------------------
>
>                 Key: LOG4NET-95
>                 URL: http://issues.apache.org/jira/browse/LOG4NET-95
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.10
>         Environment: VS2005 C#
>            Reporter: Bernd Klaiber
>         Assigned To: Ron Grabowski
>            Priority: Minor
>
> I want to show a sorted list of available Levels.
> The sort routine uses Level.Compare(Level l, Level r).
> The result might be wrong when comparing ALL to another Level, because there is an overflow when just subtracting the m_levelValue.
> try to call the integer compare method:
> Level.cs:
> 		public static int Compare(Level l, Level r)
> 		{
> 			...
>                         //orig: return l.m_levelValue - r.m_levelValue;  -> bug when int overflow
> 			return l.m_levelValue.CompareTo(r.m_levelValue);
> 		}
> hope this helps.
> best regards, Bernd.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira