Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_string_list.c
+++ new/usr/src/tools/smatch/src/smatch_string_list.c
1 1 /*
2 2 * Copyright (C) 2013 Oracle.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 #include "smatch.h"
19 19
20 20 int list_has_string(struct string_list *str_list, const char *str)
21 21 {
22 22 char *tmp;
23 + int cmp;
23 24
24 25 if (!str)
25 26 return 0;
26 27
27 28 FOR_EACH_PTR(str_list, tmp) {
28 - if (strcmp(tmp, str) < 0)
29 + cmp = strcmp(tmp, str);
30 + if (cmp < 0)
29 31 continue;
30 - if (strcmp(tmp, str) == 0)
32 + if (cmp == 0)
31 33 return 1;
32 34 return 0;
33 35 } END_FOR_EACH_PTR(tmp);
34 36 return 0;
35 37 }
36 38
37 -void insert_string(struct string_list **str_list, const char *_new)
39 +int insert_string(struct string_list **str_list, const char *_new)
38 40 {
39 41 char *new = (char *)_new;
40 42 char *tmp;
43 + int cmp;
41 44
42 45 FOR_EACH_PTR(*str_list, tmp) {
43 - if (strcmp(tmp, new) < 0)
46 + cmp = strcmp(tmp, new);
47 + if (cmp < 0)
44 48 continue;
45 - else if (strcmp(tmp, new) == 0) {
46 - return;
49 + else if (cmp == 0) {
50 + return 0;
47 51 } else {
48 52 INSERT_CURRENT(alloc_string(new), tmp);
49 - return;
53 + return 1;
50 54 }
51 55 } END_FOR_EACH_PTR(tmp);
52 56 new = alloc_string(new);
53 57 add_ptr_list(str_list, new);
58 + return 1;
54 59 }
55 60
56 61 struct string_list *clone_str_list(struct string_list *orig)
57 62 {
58 63 char *tmp;
59 64 struct string_list *ret = NULL;
60 65
61 66 FOR_EACH_PTR(orig, tmp) {
62 67 add_ptr_list(&ret, tmp);
63 68 } END_FOR_EACH_PTR(tmp);
64 69 return ret;
65 70 }
66 71
67 72 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two)
68 73 {
69 74 struct string_list *ret;
70 75 char *tmp;
71 76
72 77 ret = clone_str_list(one);
73 78 FOR_EACH_PTR(two, tmp) {
74 79 insert_string(&ret, tmp);
75 80 } END_FOR_EACH_PTR(tmp);
76 81 return ret;
77 82 }
78 83
79 84
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX