Skip to content

Checked-pointer local variable can be initialized with itself (unsound) #1194

Open
@mattmccutchen-cci

Description

@mattmccutchen-cci

While testing another issue, I made a typo and initialized a checked-pointer local variable with itself and was surprised to find that that compiles without error. An example:

#pragma CHECKED_SCOPE on

int main(void) {
  {
    // Put an invalid pointer in the memory that will be reused by `p`.
    long x = 1;
  }
  {
    _Ptr<char> p = p;
    (*p)++;  // SIGSEGV
  }
  return 0;
}

With -Wall, I get a compiler warning:

self_init.c:9:20: warning: variable 'p' is uninitialized when used within its own initialization [-Wuninitialized]
    _Ptr<char> p = p;
               ~   ^

Maybe this warning just needs to be made into an error when it occurs in the initializer of a checked-pointer variable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions