In Visual Studio 2022, I am getting the following warning when I call fwrite
.
Warning image C6387
It says: C6387:'fout' could be '0': this does not adhere to the specification for the function 'fwrite'.
Here is how I initialize the variables I pass to fwrite
.
float* fin;
FILE* fpOut = fopen("test.pcm", "wb");
int out_len = 100;
fout = malloc(256 * sizeof(float));
//... some code...
fwrite(fout, sizeof(float), out_len, fpOut); //Visual Studio underlines this full line and display the above Warning.
Am I using fwrite in an unsafe manner? Any idea how to address this warning?
Thanks in advance.
I tried to cast the type of my memory allocation of fOut, but the warning still remains.
fout = (float*)malloc(256 * sizeof(float));
I also tried to pass to fwrite
(float*)fout
and then (void*)fout
but no success.
So, I am thinking the warning has to do with the value of fout
and not its type.
I also tried using calloc
instead of malloc
to initialize fout
, but not success either.
4
Sorry for the post, ChatGPT already helped me to solve this one.
The solution is to take care of the situation when fout is not initialized properly.
if (fout == NULL)
{
fprintf(stderr, "Memory allocation failed for foutn");
return 1;
}
1