Skip to content

Inconsistent behavior with str and &str[0] #1148

@mwhicks1

Description

@mwhicks1

For this code

#include <stdio.h>
void foo(_Nt_array_ptr<char> str) {
  sprintf(str,"%s","hello");     // clang complains about incompatible type of str
  sprintf(&str[0],"%s","hello"); // no complaints
}

The stdio_checked.h file defines sprintf's first argument to be a char *. As such, passing str to it is rejected as incompatible (passing a checked type where an unchecked one was expected). But the second line is accepted, even though it is passing literally the same address to sprintf as the first. (The first line is accepted if you add an unsafe cast, e.g., sprintf((char *)str,"%s","hello");)

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