Home Page
Secure C Programming Practices
- Avoid single argument printf. If you just need to print a string, use
puts
as it will terminate with a newline character. If we must use printf() for a
string that does not terminate with a new line character, we could use %s
followed by the string replacement.
- Be aware of arithmetic overflow. Values that become too large to store into a
variable. Use limits.h defined constants to ensure that an operation that does
not overflow. Also, if a variable cannot possibly negative in a contextual
sense, use the unsigned version of it.
- Rid yourself of warnings when compiling a program.
- Always check the return value of scanf. scanf returns an integer. 1 if it was
read correctly and 0 if it was unable to parse a given value. This is useful for
checking if the user is inputting a valid value into your program, or not.
- Validate values in your program to see if they are valid.
- Bounds checking for array indices.