File: null6.c

package info (click to toggle)
splint 1%3A3.1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,012 kB
  • ctags: 23,302
  • sloc: ansic: 150,869; yacc: 3,465; sh: 3,034; makefile: 2,160; lex: 412
file content (85 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# include "bool.h"

typedef /*@null@*/ int *mnull;

extern /*@notnull@*/ mnull mnull_create (void);

extern int f1 (/*@notnull@*/ mnull x); /* 1. Function f1 declared with notnull ... */

int f (mnull x)
{
  return *x; /* 2. Possible dereference of null pointer: *x */
}

static /*@unused@*/ int f2 (/*@notnull@*/ mnull x)
{
  return *x;
}

extern /*@falsenull@*/ bool isThree (mnull x);

static /*@unused@*/ int f3 (/*@notnull@*/ mnull x)
{
  if (isThree (x)) /* the parameter was missing before 2.4! */
    {
      *x = 4;
    }
  else
    {
      *x = 5;
    }

  return (*x);
}

/*@notnull@*/ mnull f4 (void)
{
  mnull x = NULL;

  if (x == NULL)
    {
      x = mnull_create ();
    } 

  return x;
}

/*@notnull@*/ mnull f5 (void)
{
  static /*@only@*/ mnull x = NULL;

  if (x == NULL)
    {
      x = mnull_create ();
    } 

  return x;
}

/*@notnull@*/ mnull f6 (void)
{
  static /*@only@*/ mnull x = NULL;

  if (x != NULL)
    {
      x = mnull_create ();
    } 

  return x; /* 3. Possibly null storage returned as non-null */
}

/*@notnull@*/ mnull f7 (void)
{
  static /*@only@*/ mnull x = NULL;

  if (x == NULL)
    {
      x = mnull_create ();
    } 
  else
    {
      x = NULL;
    }

  return x; /* 4. Possibly null storage returned as non-null */
}