Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note that this solution correctly handles memory allocation errors in accordance with MEM32-C. Detect and handle memory allocation errors and uses the goto statement as suggested in MEM12-C. Consider using a Goto-Chain goto chain when leaving a function on error when using and releasing resources.

Implementation Details

POSIX

...

Code Block
bgColor#ffcccc
langc
int main(int argc, char *argv[])
{
FILE *out,;
FILE *in;
 
if (argc != 2) {
	/* Handle error */
}
 
in = fmemopen(argv[1], strlen(argv[1]), "r"); /* violation */
/* Use in */
 
out = open_memstream(&ptr, &size); /* violation */
/* Use out */
 
}

...

Code Block
bgColor#ccccff
langc
int main(int argc, char *argv[])
{
FILE *out,;
FILE *in;
 
if (argc != 2) {
	/* Handle error */
}
 
in = fmemopen(argv[1], strlen(argv[1]), "r");


if (in == NULL){
	/* Handle error */
}
/* Use in */
 
out = open_memstream(&ptr, &size);

if (out == NULL){
	/* Handle error */

}
/* Use out */
 
}

...