summaryrefslogtreecommitdiff
path: root/coverity/coverity_model.c
blob: a6840a6ede2c16eba8a7bf6e146429d1dc9a1551 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (C) 2015 Red Hat, Inc. All rights reserved.
 *
 * This file is part of LVM2.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License v.2.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * Coverity usage:
 *
 * translate model into xml
 * cov-make-library -of coverity_model.xml coverity_model.c
 *
 * compile (using outdir 'cov'):
 * cov-build --dir=cov make CC=gcc
 *
 * analyze (agressively, using 'cov')
 * cov-analyze --dir cov --wait-for-license --hfa --concurrency --enable-fnptr --enable-constraint-fpp --security --all --aggressiveness-level=high --field-offset-escape --user-model-file=coverity/coverity_model.xml
 *
 * generate html output (to 'html' from 'cov'):
 * cov-format-errors --dir cov  --html-output html
 */

struct lv_segment;
struct logical_volume;

struct lv_segment *first_seg(const struct logical_volume *lv)
{
	return ((struct lv_segment **)lv)[0];
}

struct lv_segment *last_seg(const struct logical_volume *lv)
{
	return ((struct lv_segment **)lv)[0];
}

const char *find_config_tree_str(struct cmd_context *cmd, int id, struct profile *profile)
{
	return "STRING";
}

/*
struct logical_volume *origin_from_cow(const struct logical_volume *lv)
{
	if (lv)
		return lv;

	__coverity_panic__();
}
*/

/* simple_memccpy() from glibc */
void *memccpy(void *dest, const void *src, int c, size_t n)
{
	const char *s = src;
	char *d = dest;

	while (n-- > 0)
		if ((*d++ = *s++) == (char) c)
			return d;

	return 0;
}

/*
 * 2 lines bellow needs to be placed in coverity/config/user_nodefs.h
 * Not sure about any other way.
 * Without them, coverity shows warning since x86 system header files
 * are using inline assembly to reset fdset
 */
//#nodef FD_ZERO model_FD_ZERO
//void model_FD_ZERO(void *fdset);

void model_FD_ZERO(void *fdset)
{
	unsigned i;

	for (i = 0; i < 1024 / 8 / sizeof(long); ++i)
		((long*)fdset)[i] = 0;
}


/* Resent Coverity reports quite weird errors... */
int *__errno_location(void)
{
}
const unsigned short **__ctype_b_loc (void)
{
}



/*
 * Added extra pointer check to not need these models,
 * for now just keep then in file
 */

/*
struct cmd_context;
struct profile;

const char *find_config_tree_str(struct cmd_context *cmd, int id, struct profile *profile)
{
        return "text";
}

const char *find_config_tree_str_allow_empty(struct cmd_context *cmd, int id, struct profile *profile)
{
        return "text";
}
*/

/*
 * Until fixed coverity case# 00531860:
 *   A FORWARD_NULL false positive on a recursive function call
 *
 * model also these functions:
 */
/*
const struct dm_config_node;
const struct dm_config_node *find_config_tree_array(struct cmd_context *cmd, int id, struct profile *profile)
{
	const struct dm_config_node *cn;

	return cn;
}

const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd, int id, struct profile *profile)
{
	const struct dm_config_node *cn;

	return cn;
}

int find_config_tree_bool(struct cmd_context *cmd, int id, struct profile *profile)
{
	int b;

	return b;
}
*/