Читать интересную книгу Основы программирования в Linux - Мэтью Нейл

Шрифт:

-
+

Интервал:

-
+

Закладка:

Сделать
1 ... 189 190 191 192 193 194 195 196 197 ... 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, где вместо предполагаемого оператора && применяется оператор &. Далее приведен отредактированный пример вывода splint, выполненной с этой версией программы. Обратите внимание на то, как она обнаруживает проблемы в строке 20 — тот факт, что вы не инициализировали переменную s и что возможны проблемы с условием из-за некорректного оператора.

[email protected]:~/BLP4e/chapter10&gt; <b>splint -strict debug0.c</b>

Splint 3.1.1 --- 19 Mar 2005

debug0.c:7:18: Read-only string literal storage used as initial value for

               unqualified storage: array[0].data = &quot;bill&quot;

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 for

               unqualified storage: array[1].data = &quot;neil&quot;

debug0.c:9:18: Read-only string literal storage used as initial value for

               unqualified storage: array[2].data = &quot;john&quot;

debug0.с:10:18: Read-only string literal storage used as initial value for

               unqualified storage: array[3].data = &quot;rick&quot;

debug0.c:11:18: Read-only string literal storage used as initial value for

               unqualified storage: array[4].data = &quot;alex&quot;

debug0.с:14:22: Old style function declaration

 Function definition is in old style syntax. Standard prototype syntax is

 preferred. (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 &amp; is not unsigned value (boolean):

               i &lt; n &amp; s != 0

 An operand to a bitwise operator is not an unsigned values. This may have

 unexpected 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 &lt; n &amp; 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 a

 modifies list for an unspecified function. (Use -modnomods to inhibit

 warning)

debug0.c:26:41: Undocumented modification of a[]: a[j + 1] = t

debug0.c:20:23: Operands of &amp; are non-integer (boolean) (in post loop test):

               i &lt; n &amp; s != 0

 A primitive operation does not type check strictly. (Use -strictops to

 inhibit warning)

debug0.с:32:14: Path with no return in function declared to return int

 There is a path through a function declared to return a value on which there

 is no return statement. This means the execution may fall through without

 returning a meaningful result to the caller. (Use -noret to inhibit

 warning)

debug0.с:34:13: Function main declared without parameter list

 A function declaration does not have a parameter list. (Use -noparams

 to inhibit warning)

debug0.с: (in function main)

debug0.с:36:22: Undocumented use of global array

 A checked global variable is used in the function, but not listed in its

 globals clause. By default, only globals specified in .lcl files are

 checked.

 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

1 ... 189 190 191 192 193 194 195 196 197 ... 324
На этом сайте Вы можете читать книги онлайн бесплатно русская версия Основы программирования в Linux - Мэтью Нейл.

Оставить комментарий