Warning C6386, as described by Microsoft, "...indicates that the writable extent of the specified buffer might be smaller than the index used to write to it. This defect can cause buffer overrun". This is the kind of programming error made by beginners (no hate, we all started somewhere). I'm looking for help from experienced (C) programmers. VS seems to think my code is capable of committing this error.
Here is the simplest case that produces this error, along with the error message:
void func(const unsigned int n)
{
unsigned int i;
float *const arr = malloc( sizeof(*arr) * n );
if (!arr) return;
for (i = 0; i < n; i++)
{
arr[i] = 3.14f; // This line produces warning C6386
}
}
// warning C6386: Buffer overrun while writing to 'arr': the writable size is 'sizeof((*arr))*n' bytes, but '8' bytes might be written.
Is this a bug within VS Code Analysis? Thanks.