musescore / musescore/MuseScore

Don't call `Shape::right()` etc. on empty shapes

Open
#24,512 0 comments 0 reactions 2 assignees View on GitHub

Nobody has claimed this yet.

tech debt
Dominant language
C++
Stars
15.1k
Forks
3.3k
Avg merge
2d 2h
Merged PRs (30d)
91

Description

See the discussion at https://github.com/musescore/MuseScore/pull/24486.

When calling Shape::right() etc. on empty shapes, ±DBL_MAX is returned, which is a bit dangerous. We could just add if (empty()) { return 0; }, but actually such methods should just not be called on empty shapes. Adding return 0; would hide the problem.

Therefore, we decided that IF_ASSERT_FAILED(!empty()) { return 0; } would be more appropriate. However, this reveals quite a number of cases where we were calling such methods on empty shapes. Some are trivially avoidable, others require a bit more thought. See https://github.com/musescore/MuseScore/compare/master...cbjeukendrup:MuseScore:zzz_backup/shape_right_assert_nonempty for an initial attempt at such fixes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.