Opened 6 years ago

Closed 6 years ago

#14725 closed defect (fixed)

suspicious code in file.cpp

Reported by: ghostvoodooman Owned by: vadz
Priority: normal Milestone:
Component: base Version: stable-latest
Keywords: file wxFile loop for ReadAll Cc:
Blocked By: Blocking:
Patch: no


There is suspicious code in ReadAll() function:

RealAll() function:

    for ( ;; )
        static const unsigned READSIZE = 4096;

        ssize_t nread = Read(p, length > READSIZE ? READSIZE : length);
        if ( nread == wxInvalidOffset )
            return false;

        p += nread;

    *p = 0;

    wxString strTmp(buf, conv);

    return true;

compiler warns about line 314 saying non-reachable code

*p = 0;

the code is not reachable, since there is infinite loop [namely "for(;;)" construct], and inside of it there is only conditional "return" statement, but no "break" statement. It is assumed the loop either loops infinitely or returns "false".

Change History (2)

comment:1 Changed 6 years ago by vadz

  • Owner set to vadz
  • Status changed from new to accepted

This is worse than suspicious, it's totally wrong :-( I forgot to finish writing this function before checking it in somehow. Fixing now, thanks for noticing this.

comment:2 Changed 6 years ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [72614]) Fix fatal bug in the recently added wxFile::ReadAll().

Make sure we exit the loop when reading the file in chunks in
wxFile::ReadAll() and add a unit test for it to ensure that it's really

Closes #14725.

Note: See TracTickets for help on using tickets.