With parser generator tools, you can easily spot syntax errors.
However, even if the syntax is in order, you should always consider that the contents may be out of order.
For example, if the file format is as follows:
- n: number of records
- record 1
- record 2
- ...
- end condition
your code should not just select an array of size n and read the entries in the array to the final condition. Instead, you should make sure that n entries were actually read (in which case, never read more than n entries to avoid overflow).
Thus, create the code so that it does not blindly trust the input.
source share