C Anti-Patterns Overview
C Anti-Patterns Overview
Not Checking Return Values
Not Checking Return Values
Buffer Overflows
Buffer Overflows
Memory Leaks
Memory Leaks
Using gets() Function
Using gets() Function
gets()
as it has no bounds checking. Use fgets()
or other bounded input functions instead.Integer Overflow
Integer Overflow
Using Uninitialized Variables
Using Uninitialized Variables
Not Using const for Read-Only Parameters
Not Using const for Read-Only Parameters
const
for function parameters that should not be modified to communicate intent and enable compiler optimizations.Using Magic Numbers
Using Magic Numbers
Using Global Variables
Using Global Variables
Not Using Header Guards
Not Using Header Guards
Using void* Without Type Checking
Using void* Without Type Checking
void*
without proper type checking. Use tagged unions or other type-safe alternatives when possible.Not Using Function Prototypes
Not Using Function Prototypes
Not Checking for NULL After Memory Allocation
Not Checking for NULL After Memory Allocation
malloc
return NULL before using the allocated memory.Using strcpy and strcat Unsafely
Using strcpy and strcat Unsafely
strcpy
and strcat
. Use bounded alternatives like strncpy
and strncat
, or better yet, use safer string handling libraries.Using Switch Statements Without Default Case
Using Switch Statements Without Default Case
Not Using Static Analysis Tools
Not Using Static Analysis Tools
Using Macros Instead of Inline Functions
Using Macros Instead of Inline Functions
Not Using Defensive Programming
Not Using Defensive Programming
Not Using Proper Error Codes
Not Using Proper Error Codes