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");)
For this code
The
stdio_checked.hfile definessprintf's first argument to be achar *. As such, passingstrto 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 tosprintfas the first. (The first line is accepted if you add an unsafe cast, e.g.,sprintf((char *)str,"%s","hello");)