Skip to content

tlXMLParser.cc:94:read(...,...) return -1 but read(...) returns size_t, which is unsigned, so this line is broken.  #1750

@shamefulCake1

Description

@shamefulCake1

The code is the following:

  size_t read (char *data, size_t n)
  {
    try {

      if (mp_progress.get ()) {
        mp_progress->set (mp_stream->pos ());
      }

      size_t n0 = n;
      for (const char *rd = 0; n > 0 && (rd = mp_stream->get (1)) != 0; --n) {
        *data++ = *rd;
      }

      if (n0 == n) {
        return -1;
      } else {
        return n0 - n;
      }

    } catch (tl::Exception &ex) {
      m_error = ex.msg ();
      m_has_error = true;
      return -1;
    }
  }

The return type of read is size_t, which cannot be negative.
return -1 is therefore equal to return UINT_MAX.

I think throwing an exception is better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions