Value types *can* still be constructed in an invalid state

Open
#1,786 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
tooling

Research direction

Start by reproducing the ValueType example from the issue, including default construction and the later string_member assignment, then review the change in #1783 for related initialization behavior. The fix is complete when a default-constructed ValueType cannot produce garbage on subsequent reads after assignment.

Written by the indexing model from the issue text.

Description

Even following #1783, the following value type:

CS_VALUE_TYPE class DLL_API ValueType {
public:
    std::string string_member;
};

can be constructed in an invalid state, e.g. by using ValueType v = default;

Following v.string_member = "..."; resulting reads will result in garbage being read.

A remedy could be a variable to track whether the object was initialized and if not initializing it whenever any operation is called on it.

Dominant language
C#
Stars
3.4k
Forks
541
PR merge metrics
No merged PRs in 30d

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.

More from mono/CppSharp

All issues in mono/CppSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.