splint

C和C++安全编码笔记:整数安全

送分小仙女□ 提交于 2020-08-11 10:34:20
5.1 整数安全导论:整数由包括0的自然数(0, 1, 2, 3, …)和非零自然数的负数(-1, -2, -3, …)构成。 5.2 整数数据类型:整数类型提供了整数数学集合的一个有限子集的模型。一个具有整数类型的对象的值是附着在这个对象上的数学值。一个具有整数类型的对象的值的表示方式(representation)是在为该对象分配的存储空间中该值的特定位模式编码。 在C中每个整数类型的对象需要一个固定的存储字节数。<limits.h>头文件中的常量表达式CHAR_BIT,给出了一个字节中的位数,它必须至少为8,但可能会更大,这取决于具体的实现。除unsigned char型外,不是所有的位都必须用来表示值,未使用的位被称为填充(padding)。 标准的整数类型由一组有符号的整数类型和相应的无符号整数类型组成。 无符号整数类型:C要求无符号整数类型值使用无偏移的纯二进制系统表示。无符号整数是计数器的自然选择。标准的无符号整数类型(按照它们的长度非递减排序)是:unsigned char、unsigned short int、unsigned int、unsigned long int、unsigned long long int,关键字int可以省略,除非它是唯一存在的整数类型的关键字。 特定于编译器和平台的整数极值记录在<limits.h> 头文件中

Non-standard function return types: Fixing Splint parse error

随声附和 提交于 2019-12-14 02:40:42
问题 I'm using the embedded-system XC8 C compiler (for PIC microprocessors). The following is allowed: bit foo(){ //... } but being non-standard C, the Splint static analyser gives the following error: Parse Error: Non-function declaration: bit : "--------------------------------------" int. And the file/line of the error is the function prototype in the respective .h file. How can I fix this so Splint can analyse the rest of the file(s)? I think there might be two ways: I think I remember seeing

Transfer ownership of storage in Splint

孤者浪人 提交于 2019-12-13 00:42:52
问题 Using a simple linked list implementation in C, how do I tell Splint that I am transfer ownership of data ? typedef struct { void* data; /*@null@*/ void* next; } list; static /*@null@*/ list* new_list(/*@notnull@*/ void* data) { list* l; l = malloc(sizeof(list)); if (l == NULL) return NULL; l->next = NULL; l->data = data; return l; } I get this error message: Implicitly temp storage data assigned to implicitly only: list->data = data Temp storage (associated with a formal parameter) is

Recommended way to track down array out-of-bound access/write in C program

末鹿安然 提交于 2019-11-27 23:31:36
Consider writing implementation for some not-so-obvious algorithm in C. For example let it be recursive quicksort, that I have found in K. N. King's "C Programming: A Modern Approach, 2nd Edition" book, that it's available from here . The most interesting part consist of two following definitions: void quicksort(int a[], int low, int high) { int middle; if (low >= high) return; middle = split(a, low, high); quicksort(a, low, middle - 1); quicksort(a, middle + 1, high); } int split(int a[], int low, int high) { int part_element = a[low]; for (;;) { while (low < high && part_element <= a[high])

Recommended way to track down array out-of-bound access/write in C program

寵の児 提交于 2019-11-26 21:14:58
问题 Consider writing implementation for some not-so-obvious algorithm in C. For example let it be recursive quicksort, that I have found in K. N. King's "C Programming: A Modern Approach, 2nd Edition" book, that it's available from here. The most interesting part consist of two following definitions: void quicksort(int a[], int low, int high) { int middle; if (low >= high) return; middle = split(a, low, high); quicksort(a, low, middle - 1); quicksort(a, middle + 1, high); } int split(int a[], int