...
The following piece of code validates the number of command line arguemnts. If the correct number of commmand line arguments have been specified, then the requested amount of memory is validated to assure it is a acceptable size and the memory allocated with malloc()
and referenced by str
. 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.
...