Author Topic: codecompletion warnings under ANSI Windows  (Read 7292 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7323
    • My Best Post
codecompletion warnings under ANSI Windows
« on: March 08, 2011, 06:48:48 pm »
I have about a dozen warnings when Compiling Code::Blocks under Windows with ANSI (Non Unicode) Build of trunk.
Does anybody care?

Edit: All dozen seem to be cause by the same line of code in the header.

Tim S.

Example warning below.
Code
src\plugins\codecompletion\parser\token.h|96|warning: format '%d' expects type 'int', but argument 4 has type 'long int'|

Patch

Code
Index: src/plugins/codecompletion/parser/token.h
===================================================================
--- src/plugins/codecompletion/parser/token.h (revision 7041)
+++ src/plugins/codecompletion/parser/token.h (working copy)
@@ -88,7 +88,7 @@
         {
             const long totalTime = it->first->m_StopWatch.Time();
             wxString log;
-            log.Printf(_T("\"%s\" used time is %d minute(s), %ld.%03ld seconds; call times is %d."),
+            log.Printf(_T("\"%s\" used time is %ld minute(s), %ld.%03ld seconds; call times is %d."),
                        it->second.wx_str(),
                        (totalTime / 60000),
                        (totalTime / 1000) % 60,
« Last Edit: March 08, 2011, 06:54:42 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: codecompletion warnings under ANSI Windows
« Reply #1 on: March 08, 2011, 06:52:24 pm »
Me cares, on linux 64bit int is 32bit, long int is 64bit, so these are real errors, especially when used for non-logging purposes.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: codecompletion warnings under ANSI Windows
« Reply #2 on: March 08, 2011, 07:34:37 pm »
There are more (potential dangerous or at least error-prone) warnings (compiled with -Wextra):
Quote
/home/jens/codeblocks-build/codeblocks.trunk/src/plugins/codecompletion/parser/tokenizer.h:358:36: warning: comparison of unsigned expression < 0 is always false
Quote
    /** Return (peek) the previous character */
    wxChar PreviousChar() const
    {
        if ( ((m_TokenIndex - 1) < 0) || (m_BufferLen==0) ) // (m_TokenIndex - 1) >= m_BufferLen can never be true
            return 0;

        return m_Buffer.GetChar(m_TokenIndex - 1);
    };
and
Quote
/home/jens/codeblocks-build/codeblocks.trunk/src/plugins/codecompletion/parser/tokenizer.h:391:51: warning: comparison of unsigned expression >= 0 is always true
Quote
    /** Check the previous char before EOL is a backslash */
    inline bool IsBackslashBeforeEOL()
    {
        wxChar last = PreviousChar();
        // if DOS line endings, we 've hit \r and we skip to \n...
        if (last == _T('\r') && (m_TokenIndex - 2 >= 0))
            return m_Buffer.GetChar(m_TokenIndex - 2) == _T('\\');
        return last == _T('\\');
    }

Code
    unsigned int         m_TokenIndex;

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9660
Re: codecompletion warnings under ANSI Windows
« Reply #3 on: March 08, 2011, 08:33:38 pm »
There are more (potential dangerous or at least error-prone) warnings (compiled with -Wextra):
So what about:
Quote
   /** Return (peek) the previous character */
    wxChar PreviousChar() const
    {
        if ( (m_TokenIndex==0) || (m_BufferLen==0) ) // (m_TokenIndex - 1) >= m_BufferLen can never be true
            return 0;

        return m_Buffer.GetChar(m_TokenIndex - 1);
    };
and
Quote
   /** Check the previous char before EOL is a backslash */
    inline bool IsBackslashBeforeEOL()
    {
        wxChar last = PreviousChar();
        // if DOS line endings, we 've hit \r and we skip to \n...
        if (last == _T('\r') && (m_TokenIndex > 1))
            return m_Buffer.GetChar(m_TokenIndex - 2) == _T('\\');
        return last == _T('\\');
    }
???
« Last Edit: March 08, 2011, 08:35:10 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ