...
Non-Compliant Code Example
The following This piece of code validates the number of command line arguments. If the correct number of commmand line arguments have been specified, the requested amount of memory is validated to ensure that it is an acceptable size, and the memory is allocated with malloc()
. Next, the second command line argument is copied into str
for further processing. Once this processing is complete, str
is freed. However, if the incorrect number of arguments have been specified, str
is set to a string literal and printed. Because str
now references memory that was not dynamically allocated, an error will occur when str
memory is freed.
...