安全
整数溢出
缓冲区溢出
使用安全的内存操作函数
不要使用 strcpy, strcat, sprint
,应该使用 strncpy, strncat, snprint
- 使用
strncpy
和strncat
时size = n - 1
,且末尾设为\0
使用 memcpy
前应该检查 n
不能使用 memcmp
比较两个结构体,因为存在内存对齐。
其他
不应该使用 printf(buffer)
,应该 printf("%s", buffer)
,因为 buffer
中可能有特殊字符 %