Bug Summary

File:gromacs/gmxlib/symtab.c
Location:line 97, column 5
Description:Value stored to 'index' is never read

Annotated Source Code

1/*
2 * This file is part of the GROMACS molecular simulation package.
3 *
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
10 *
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
15 *
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 *
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
33 *
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
36 */
37#ifdef HAVE_CONFIG_H1
38#include <config.h>
39#endif
40
41#include <stdio.h>
42#include <string.h>
43#include "typedefs.h"
44#include "gromacs/utility/fatalerror.h"
45#include "gromacs/utility/smalloc.h"
46#include "txtdump.h"
47#include "symtab.h"
48#include "macros.h"
49
50#define BUFSIZE1024 1024
51#define TABLESIZE5 5
52
53static char *trim_string(const char *s, char *out, int maxlen)
54/*
55 * Returns a pointer to a static area which contains a copy
56 * of s without leading or trailing spaces. Strings are
57 * truncated to BUFSIZE positions.
58 */
59{
60 int len, i;
61
62 if (strlen(s) > (size_t)(maxlen-1))
63 {
64 gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 64
, "String '%s' (%d) is longer than buffer (%d).\n",
65 s, strlen(s), maxlen-1);
66 }
67
68 for (; (*s) && ((*s) == ' '); s++)
69 {
70 ;
71 }
72 for (len = strlen(s); (len > 0); len--)
73 {
74 if (s[len-1] != ' ')
75 {
76 break;
77 }
78 }
79 if (len >= BUFSIZE1024)
80 {
81 len = BUFSIZE1024-1;
82 }
83 for (i = 0; i < len; i++)
84 {
85 out[i] = *(s++);
86 }
87 out[i] = 0;
88 return out;
89}
90
91int lookup_symtab(t_symtab *symtab, char **name)
92{
93 int base, index;
94 t_symbuf *symbuf;
95
96 base = 0;
97 index = 0;
Value stored to 'index' is never read
98 symbuf = symtab->symbuf;
99 while (symbuf != NULL((void*)0))
100 {
101 index = name-symbuf->buf;
102 if ( ( index >= 0 ) && ( index < symbuf->bufsize ) )
103 {
104 return index+base;
105 }
106 else
107 {
108 base += symbuf->bufsize;
109 symbuf = symbuf->next;
110 }
111 }
112 gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 112
, "symtab lookup \"%s\" not found", *name);
113 return -1;
114}
115
116char **get_symtab_handle(t_symtab *symtab, int name)
117{
118 t_symbuf *symbuf;
119
120 symbuf = symtab->symbuf;
121 while (symbuf != NULL((void*)0))
122 {
123 if (name < symbuf->bufsize)
124 {
125 return &(symbuf->buf[name]);
126 }
127 else
128 {
129 name -= symbuf->bufsize;
130 symbuf = symbuf->next;
131 }
132 }
133 gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 133
, "symtab get_symtab_handle %d not found", name);
134 return NULL((void*)0);
135}
136
137static t_symbuf *new_symbuf(void)
138{
139 t_symbuf *symbuf;
140
141 snew(symbuf, 1)(symbuf) = save_calloc("symbuf", "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 141, (1), sizeof(*(symbuf)))
;
142 symbuf->bufsize = TABLESIZE5;
143 snew(symbuf->buf, symbuf->bufsize)(symbuf->buf) = save_calloc("symbuf->buf", "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 143, (symbuf->bufsize), sizeof(*(symbuf->buf)))
;
144 symbuf->next = NULL((void*)0);
145
146 return symbuf;
147}
148
149static char **enter_buf(t_symtab *symtab, char *name)
150{
151 int i;
152 t_symbuf *symbuf;
153 gmx_bool bCont;
154
155 if (symtab->symbuf == NULL((void*)0))
156 {
157 symtab->symbuf = new_symbuf();
158 }
159
160 symbuf = symtab->symbuf;
161 do
162 {
163 for (i = 0; (i < symbuf->bufsize); i++)
164 {
165 if (symbuf->buf[i] == NULL((void*)0))
166 {
167 symtab->nr++;
168 symbuf->buf[i] = strdup(name)(__extension__ (__builtin_constant_p (name) && ((size_t
)(const void *)((name) + 1) - (size_t)(const void *)(name) ==
1) ? (((const char *) (name))[0] == '\0' ? (char *) calloc (
(size_t) 1, (size_t) 1) : ({ size_t __len = strlen (name) + 1
; char *__retval = (char *) malloc (__len); if (__retval != (
(void*)0)) __retval = (char *) memcpy (__retval, name, __len)
; __retval; })) : __strdup (name)))
;
169 return &(symbuf->buf[i]);
170 }
171 else if (strcmp(symbuf->buf[i], name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(symbuf->buf[i]) && __builtin_constant_p (name) &&
(__s1_len = strlen (symbuf->buf[i]), __s2_len = strlen (name
), (!((size_t)(const void *)((symbuf->buf[i]) + 1) - (size_t
)(const void *)(symbuf->buf[i]) == 1) || __s1_len >= 4)
&& (!((size_t)(const void *)((name) + 1) - (size_t)(
const void *)(name) == 1) || __s2_len >= 4)) ? __builtin_strcmp
(symbuf->buf[i], name) : (__builtin_constant_p (symbuf->
buf[i]) && ((size_t)(const void *)((symbuf->buf[i]
) + 1) - (size_t)(const void *)(symbuf->buf[i]) == 1) &&
(__s1_len = strlen (symbuf->buf[i]), __s1_len < 4) ? (
__builtin_constant_p (name) && ((size_t)(const void *
)((name) + 1) - (size_t)(const void *)(name) == 1) ? __builtin_strcmp
(symbuf->buf[i], name) : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (name); int
__result = (((const unsigned char *) (const char *) (symbuf->
buf[i]))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
symbuf->buf[i]))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (symbuf->buf[i]))[2] - __s2[2]); if (__s1_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) (symbuf->buf[i]))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p (name) && ((size_t)(const
void *)((name) + 1) - (size_t)(const void *)(name) == 1) &&
(__s2_len = strlen (name), __s2_len < 4) ? (__builtin_constant_p
(symbuf->buf[i]) && ((size_t)(const void *)((symbuf
->buf[i]) + 1) - (size_t)(const void *)(symbuf->buf[i])
== 1) ? __builtin_strcmp (symbuf->buf[i], name) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (symbuf->buf[i]); int __result = (((const unsigned
char *) (const char *) (name))[0] - __s2[0]); if (__s2_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) (name))[1] - __s2[1]); if (__s2_len > 1
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (name))[2] - __s2[2]); if (__s2_len > 2
&& __result == 0) __result = (((const unsigned char *
) (const char *) (name))[3] - __s2[3]); } } __result; })))) :
__builtin_strcmp (symbuf->buf[i], name)))); })
== 0)
172 {
173 return &(symbuf->buf[i]);
174 }
175 }
176 if (symbuf->next != NULL((void*)0))
177 {
178 symbuf = symbuf->next;
179 bCont = TRUE1;
180 }
181 else
182 {
183 bCont = FALSE0;
184 }
185 }
186 while (bCont);
187
188 symbuf->next = new_symbuf();
189 symbuf = symbuf->next;
190
191 symtab->nr++;
192 symbuf->buf[0] = strdup(name)(__extension__ (__builtin_constant_p (name) && ((size_t
)(const void *)((name) + 1) - (size_t)(const void *)(name) ==
1) ? (((const char *) (name))[0] == '\0' ? (char *) calloc (
(size_t) 1, (size_t) 1) : ({ size_t __len = strlen (name) + 1
; char *__retval = (char *) malloc (__len); if (__retval != (
(void*)0)) __retval = (char *) memcpy (__retval, name, __len)
; __retval; })) : __strdup (name)))
;
193 return &(symbuf->buf[0]);
194}
195
196char **put_symtab(t_symtab *symtab, const char *name)
197{
198 char buf[1024];
199
200 return enter_buf(symtab, trim_string(name, buf, 1023));
201}
202
203void open_symtab(t_symtab *symtab)
204{
205 symtab->nr = 0;
206 symtab->symbuf = NULL((void*)0);
207}
208
209void close_symtab(t_symtab gmx_unused__attribute__ ((unused)) *symtab)
210{
211}
212
213void done_symtab(t_symtab *symtab)
214{
215 int i;
216 t_symbuf *symbuf, *freeptr;
217
218 close_symtab(symtab);
219 symbuf = symtab->symbuf;
220 while (symbuf != NULL((void*)0))
221 {
222 for (i = 0; (i < symbuf->bufsize) && (i < symtab->nr); i++)
223 {
224 sfree(symbuf->buf[i])save_free("symbuf->buf[i]", "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 224, (symbuf->buf[i]))
;
225 }
226 symtab->nr -= i;
227 sfree(symbuf->buf)save_free("symbuf->buf", "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 227, (symbuf->buf))
;
228 freeptr = symbuf;
229 symbuf = symbuf->next;
230 sfree(freeptr)save_free("freeptr", "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 230, (freeptr))
;
231 }
232 symtab->symbuf = NULL((void*)0);
233 if (symtab->nr != 0)
234 {
235 gmx_incons("Freeing symbol table (symtab) structure")_gmx_error("incons", "Freeing symbol table (symtab) structure"
, "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c",
235)
;
236 }
237}
238
239void free_symtab(t_symtab *symtab)
240{
241 t_symbuf *symbuf, *freeptr;
242
243 close_symtab(symtab);
244 symbuf = symtab->symbuf;
245 while (symbuf != NULL((void*)0))
246 {
247 symtab->nr -= min(symbuf->bufsize, symtab->nr)(((symbuf->bufsize) < (symtab->nr)) ? (symbuf->bufsize
) : (symtab->nr) )
;
248 freeptr = symbuf;
249 symbuf = symbuf->next;
250 sfree(freeptr)save_free("freeptr", "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c"
, 250, (freeptr))
;
251 }
252 symtab->symbuf = NULL((void*)0);
253 if (symtab->nr != 0)
254 {
255 gmx_incons("Freeing symbol table (symtab) structure")_gmx_error("incons", "Freeing symbol table (symtab) structure"
, "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c",
255)
;
256 }
257}
258
259void pr_symtab(FILE *fp, int indent, const char *title, t_symtab *symtab)
260{
261 int i, j, nr;
262 t_symbuf *symbuf;
263
264 if (available(fp, symtab, indent, title))
265 {
266 indent = pr_title_n(fp, indent, title, symtab->nr);
267 i = 0;
268 nr = symtab->nr;
269 symbuf = symtab->symbuf;
270 while (symbuf != NULL((void*)0))
271 {
272 for (j = 0; (j < symbuf->bufsize) && (j < nr); j++)
273 {
274 pr_indent(fp, indent);
275 (void) fprintf(fp, "%s[%d]=\"%s\"\n", title, i++, symbuf->buf[j]);
276 }
277 nr -= j;
278 symbuf = symbuf->next;
279 }
280 if (nr != 0)
281 {
282 gmx_incons("Printing symbol table (symtab) structure")_gmx_error("incons", "Printing symbol table (symtab) structure"
, "/home/alexxy/Develop/gromacs/src/gromacs/gmxlib/symtab.c",
282)
;
283 }
284 }
285}