Основы программирования в Linux
Часть 193 из 324 Информация о книге
/* 17 */ int i = 0, j = 0;/* 18 */ int s;/* 19 *//* 20 */ for(; i < n & s != 0; i++) {/* 21 */ s = 0;/* 22 */ for(j = 0; j < n; j++) {/* 23 */ if(a[j].key > a[j+1].key) {/* 24 */ item t = a[j];/* 25 */ a[j] = a[j+1];/* 26 */ a[j+1] = t;/* 27 */ s++;/* 28 */ }/* 29 */ }/* 30 */ n--;/* 31 */ }/* 32 */ }/* 33 *//* 34 */ main()/* 35 */ {/* 36 */ sort(array,5);/* 37 */ }В этой версии есть проблема в строке 20, где вместо предполагаемого оператора
применяется оператор&&. Далее приведен отредактированный пример вывода&, выполненной с этой версией программы. Обратите внимание на то, как она обнаруживает проблемы в строке 20 — тот факт, что вы не инициализировали переменнуюsplintи что возможны проблемы с условием из-за некорректного оператора.s[email protected]:~/BLP4e/chapter10> <b>splint -strict debug0.c</b>Splint 3.1.1 --- 19 Mar 2005debug0.c:7:18: Read-only string literal storage used as initial value forunqualified storage: array[0].data = "bill"A read-only string literal is assigned to a non-observer reference. (Use -readonlytrans to inhibit warning)debug0.c:8:18: Read-only string literal storage used as initial value forunqualified storage: array[1].data = "neil"debug0.c:9:18: Read-only string literal storage used as initial value forunqualified storage: array[2].data = "john"debug0.с:10:18: Read-only string literal storage used as initial value forunqualified storage: array[3].data = "rick"debug0.c:11:18: Read-only string literal storage used as initial value forunqualified storage: array[4].data = "alex"debug0.с:14:22: Old style function declarationFunction definition is in old style syntax. Standard prototype syntax ispreferred. (Use -oldstyle to inhibit warning)debug0.с: (in function sort)<i>debug0.c:20:31: Variable s used before definition</i><i> An rvalue is used that may not be initialized to a value on some execution</i><i> path. (Use -usedef to inhibit warning)</i>debug0.с:20:23: Left operand of & is not unsigned value (boolean):i < n & s != 0An operand to a bitwise operator is not an unsigned values. This may haveunexpected results depending on the signed representations. (Use-bitwisesigned to inhibit warning).<i>debug0.c:20:23: Test expression for for not boolean, type unsigned int:</i><i> i < n & s != 0</i><i> Test expression type is not boolean or int. (Use -predboolint to inhibit </i><i> warning);</i>debug0.с:25:41: Undocumented modification of a[]: a[j] = a[j + 1]An externally-visible object is modified by a function with no /*@[email protected]*/comment. The /*@modifies ... @*/ control comment can be used to give amodifies list for an unspecified function. (Use -modnomods to inhibitwarning)debug0.c:26:41: Undocumented modification of a[]: a[j + 1] = tdebug0.c:20:23: Operands of & are non-integer (boolean) (in post loop test):i < n & s != 0A primitive operation does not type check strictly. (Use -strictops toinhibit warning)debug0.с:32:14: Path with no return in function declared to return intThere is a path through a function declared to return a value on which thereis no return statement. This means the execution may fall through withoutreturning a meaningful result to the caller. (Use -noret to inhibitwarning)debug0.с:34:13: Function main declared without parameter listA function declaration does not have a parameter list. (Use -noparamsto inhibit warning)debug0.с: (in function main)debug0.с:36:22: Undocumented use of global arrayA checked global variable is used in the function, but not listed in itsglobals clause. By default, only globals specified in .lcl files arechecked.To check all globals, use +allglobals. To check globals selectively use/*@[email protected]*/ in the global declaration. (Use -globs to inhibit warning)debug0.с:36:17: Undetected modification possible from call to unconstrained