Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shamefulCake1 opened this issue Jun 21, 2024 · 1 comment · Fixed by #1752
Labels
Milestone

Comments

@shamefulCake1
Copy link

shamefulCake1 commented Jun 21, 2024

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.

@klayoutmatthias
Copy link
Collaborator

This is only for EXPAT binding, but it is worth fixing it.

Thanks.

Matthias

@klayoutmatthias klayoutmatthias added this to the 0.29.3 milestone Jun 22, 2024
klayoutmatthias pushed a commit that referenced this issue Jun 22, 2024
@klayoutmatthias klayoutmatthias linked a pull request Jun 22, 2024 that will close this issue
klayoutmatthias added a commit that referenced this issue Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants