I found an apparent bug in valnum.cpp

Building and customizing Audacity from the source code.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
RandomTroll
Posts: 15
Joined: Tue Jan 12, 2010 5:53 am
Operating System: GNU/Linux other

I found an apparent bug in valnum.cpp

Post by RandomTroll » Thu Dec 25, 2014 5:52 am

This bit of code from valnum.cpp declares c inside a conditional but uses it outside the conditional. Moving its declaration outside the conditional allowed compiling.

Code: Select all


void wxNumValidatorBase::OnChar(wxKeyEvent& event)
{
    // By default we just validate this key so don't prevent the normal
    // handling from taking place.
    event.Skip();

    if ( !m_validatorWindow )
        return;

#if wxUSE_UNICODE
    const int ch = event.GetUnicodeKey();
    const int c = event.GetKeyCode();
    if ( c > WXK_START )
    {
        // It's a character without any Unicode equivalent at all, e.g. cursor
        // arrow or function key, we never filter those.
        return;
    }
#else // !wxUSE_UNICODE
    const int ch = event.GetKeyCode();
    if ( ch > WXK_DELETE )
    {
        // Not a character neither.
        return;
    }
#endif // wxUSE_UNICODE/!wxUSE_UNICODE

    if ( c < WXK_SPACE || c == WXK_DELETE )
    {
        // Allow ASCII control characters and Delete.
        return;
    }

steve
Site Admin
Posts: 47287
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Re: I found an apparent bug in valnum.cpp

Post by steve » Thu Dec 25, 2014 1:18 pm

Thanks for the report.
I'll pass this on to the developers.

I agree that this is an error, but I'm surprised that it caused a problem because (normally) we should be using Unicode.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

RandomTroll
Posts: 15
Joined: Tue Jan 12, 2010 5:53 am
Operating System: GNU/Linux other

Re: I found an apparent bug in valnum.cpp

Post by RandomTroll » Thu Dec 25, 2014 5:26 pm

I figured that, being the first person to report this bug so late in the day, and it only happens to people not compiling for unicode, I must be the first to try. I don't disable unicode with configure; it's enabled by default, so I don't know why this happened to me.

steve
Site Admin
Posts: 47287
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Re: I found an apparent bug in valnum.cpp

Post by steve » Sun Dec 28, 2014 8:10 pm

A fix for the "valnum" bug has just been committed into the current "alpha" code.
If you're interested, this is what was committed:

Code: Select all

Modified:
  /audacity-src/trunk/src/widgets/valnum.cpp

=======================================
--- /audacity-src/trunk/src/widgets/valnum.cpp        Sun Nov 16 13:39:18 2014 UTC
+++ /audacity-src/trunk/src/widgets/valnum.cpp        Sun Dec 28 20:02:00 2014 UTC
@@ -159,6 +159,7 @@
      }
  #else // !wxUSE_UNICODE
      const int ch = event.GetKeyCode();
+    const int c = ch;
      if ( ch > WXK_DELETE )
      {
          // Not a character neither. 

Post Reply