clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name avlRead_BODY.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I avlmrf -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-dangling-else -Wno-parentheses -Wno-unused-result -Wno-format-truncation -Wno-unused-function -fdebug-compilation-dir /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/CAPS/aim/avl -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/scanCAPS/2022-03-16-174428-58004-1 -x c avlmrf/avlRead_BODY.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | #include "avlRead_BODY.h" |
22 | #define AVL_MRF_INTERNAL |
23 | #include "read_util.h" |
24 | |
25 | |
26 | |
27 | |
28 | int avlRead_BODY( const char *filename, avlBody *body, bool verbose ) |
29 | { |
30 | int n, ibody; |
31 | char *string = NULL, *version = NULL; |
32 | double val[9]; |
33 | bool isOK; |
34 | size_t stringsize = 128; |
35 | FILE *fp = NULL; |
36 | avlLineBuffer line; |
37 | line.line = NULL; |
38 | line.linesize = 0; |
39 | |
40 | if (body == NULL) return -1; |
| 1 | Assuming 'body' is not equal to NULL | |
|
| |
41 | |
42 | avlFree_BODY( body ); |
43 | |
44 | fp = fopen( filename, "r" ); |
45 | if (fp == NULL) |
| 3 | | Assuming 'fp' is not equal to NULL | |
|
| |
46 | { |
47 | printf( "ERROR: unable to open %s\n", filename ); |
48 | return -1; |
49 | } |
50 | |
51 | string = (char *) malloc( stringsize * sizeof(char) ); |
52 | if (string == NULL) |
| 5 | | Assuming 'string' is not equal to NULL | |
|
| |
53 | { |
54 | printf( "ERROR: malloc error on 'string'\n" ); |
55 | goto error; |
56 | } |
57 | |
58 | version = (char *) malloc( stringsize * sizeof(char) ); |
59 | if (version == NULL) |
| 7 | | Assuming 'version' is not equal to NULL | |
|
| |
60 | { |
61 | printf( "ERROR: malloc error on 'version'\n" ); |
62 | goto error; |
63 | } |
64 | |
65 | |
66 | isOK = getLine_string1( fp, "BODY", &line, string ); |
| 9 | | Calling 'getLine_string1' | |
|
| 14 | | Returning from 'getLine_string1' | |
|
67 | if (isOK) |
| |
68 | { |
69 | if (strcmp(string, "BODY") != 0) |
| 16 | | Assuming the condition is false | |
|
| |
70 | { |
71 | printf( "ERROR in %s: expected 'BODY' file ID but got '%s'\n", __func__, string ); |
72 | goto error; |
73 | } |
74 | if (verbose) printf( "%s\n", string ); |
| 18 | | Assuming 'verbose' is true | |
|
| |
75 | } |
76 | else |
77 | goto error; |
78 | |
79 | |
80 | isOK = getLine_string2( fp, "VERSION", &line, string, version ); |
| 20 | | Calling 'getLine_string2' | |
|
| 25 | | Returning from 'getLine_string2' | |
|
81 | if (isOK) |
| |
82 | { |
83 | if (strcmp(string, "VERSION") != 0) |
| 27 | | Assuming the condition is false | |
|
| |
84 | { |
85 | printf( "ERROR: expected VERSION keyword but got '%s'\n", string ); |
86 | goto error; |
87 | } |
88 | if (strcmp(version, "1.0") != 0) |
| 29 | | Assuming the condition is false | |
|
| |
89 | { |
90 | printf( "ERROR: unexpected VERSION number '%s'\n", version ); |
91 | goto error; |
92 | } |
93 | if (verbose) printf( "VERSION = %s\n", version ); |
| |
94 | } |
95 | else |
96 | goto error; |
97 | |
98 | |
99 | isOK = getLine_line( fp, &line ); |
| |
| 35 | | Returning from 'getLine_line' | |
|
100 | if (isOK) |
| |
101 | { |
102 | if (verbose) printf( "%s\n", chop_newline(line.line) ); |
| |
103 | } |
104 | else |
105 | goto error; |
106 | |
107 | |
108 | isOK = getLine_real3( fp, "Sref, Cref, Bref", &line, &body->Sref, &body->Cref, &body->Bref ); |
| 38 | | Calling 'getLine_real3' | |
|
| 43 | | Returning from 'getLine_real3' | |
|
109 | if (isOK) |
| |
110 | { |
111 | if (verbose) printf( "Sref = %lf Cref = %lf Bref = %lf\n", body->Sref, body->Cref, body->Bref ); |
| |
112 | } |
113 | else |
114 | goto error; |
115 | |
116 | |
117 | isOK = getLine_real3( fp, "Xref, Yref, Zref", &line, &body->Xref, &body->Yref, &body->Zref ); |
| 46 | | Calling 'getLine_real3' | |
|
| 51 | | Returning from 'getLine_real3' | |
|
118 | if (isOK) |
| |
119 | { |
120 | if (verbose) printf( "Xref = %lf Yref = %lf Zref = %lf\n", body->Xref, body->Yref, body->Zref ); |
| |
121 | } |
122 | else |
123 | goto error; |
124 | |
125 | |
126 | body->nbody = 0; |
127 | isOK = getLine_int1( fp, "# of bodies", &line, &body->nbody ); |
| |
| 59 | | Returning from 'getLine_int1' | |
|
128 | if (isOK) |
| |
129 | { |
130 | if (verbose) printf( "# bodies = %d\n", body->nbody ); |
| |
131 | } |
132 | else |
133 | goto error; |
134 | |
135 | |
136 | body->body = (avlBodyProp *) malloc( body->nbody * sizeof(avlBodyProp) ); |
| 62 | | Uninitialized value stored to field 'Length' | |
|
137 | if (body->body == NULL) |
| 63 | | Assuming field 'body' is not equal to NULL | |
|
| |
138 | { |
139 | body->nbody = 0; |
140 | printf( "ERROR: malloc error on 'avlBodyProp'\n" ); |
141 | goto error; |
142 | } |
143 | for (ibody = 0; ibody < body->nbody; ibody++) |
| 65 | | Assuming 'ibody' is < field 'nbody' | |
|
| 66 | | Loop condition is true. Entering loop body | |
|
| 67 | | Assuming 'ibody' is >= field 'nbody' | |
|
| 68 | | Loop condition is false. Execution continues on line 147 | |
|
144 | body->body[ibody].name = NULL; |
145 | |
146 | |
147 | for (ibody = 0; ibody < body->nbody; ibody++) |
| 69 | | Loop condition is true. Entering loop body | |
|
148 | { |
149 | |
150 | isOK = getLine_string1( fp, "BODY", &line, string ); |
| 70 | | Calling 'getLine_string1' | |
|
| 75 | | Returning from 'getLine_string1' | |
|
151 | if (isOK) |
| |
152 | { |
153 | if (strcmp(string, "BODY") != 0) |
| 77 | | Assuming the condition is false | |
|
| |
154 | { |
155 | printf( "ERROR: expected BODY keyword but got '%s'\n", string ); |
156 | goto error; |
157 | } |
158 | if (verbose) printf( "%s\n", string ); |
| |
159 | } |
160 | else |
161 | goto error; |
162 | |
163 | |
164 | isOK = getLine_line( fp, &line ); |
| |
| 83 | | Returning from 'getLine_line' | |
|
165 | if (isOK) |
| |
166 | { |
167 | body->body[ibody].name = strdup(chop_newline(line.line)); |
168 | if (body->body[ibody].name == NULL) goto error; |
| 85 | | Assuming field 'name' is not equal to NULL | |
|
| |
169 | if (verbose) printf( "%s\n", body->body[ibody].name ); |
| |
170 | } |
171 | else |
172 | goto error; |
173 | |
174 | |
175 | |
176 | isOK = getLine_int1_realn( fp, "Ibdy Length Asurf Vol CL CD Cm CY Cn Cl", &line, &n, val, 9 ); |
177 | if (isOK) |
| 88 | | Assuming 'isOK' is true | |
|
| |
178 | { |
179 | body->body[ibody].Length = val[0]; |
180 | body->body[ibody].Asurf = val[1]; |
181 | body->body[ibody].Vol = val[2]; |
182 | body->body[ibody].CL = val[3]; |
183 | body->body[ibody].CD = val[4]; |
184 | body->body[ibody].Cm = val[5]; |
185 | body->body[ibody].CY = val[6]; |
186 | body->body[ibody].Cn = val[7]; |
187 | body->body[ibody].Cl = val[8]; |
188 | if (verbose) |
| |
189 | { |
190 | printf( "%d Length = %lf Asurf = %lf Vol = %lf CL = %lf ", n, |
| 91 | | 3rd function call argument is an uninitialized value |
|
191 | body->body[n-1].Length, |
192 | body->body[n-1].Asurf, |
193 | body->body[n-1].Vol, |
194 | body->body[n-1].CL ); |
195 | printf( "CD = %lf Cm = %lf CY = %lf Cn = %lf Cl = %lf\n", body->body[n-1].CD, |
196 | body->body[n-1].Cm, |
197 | body->body[n-1].CY, |
198 | body->body[n-1].Cn, |
199 | body->body[n-1].Cl ); |
200 | } |
201 | } |
202 | else |
203 | goto error; |
204 | } |
205 | |
206 | avl_free( line.line ); |
207 | avl_free( string ); |
208 | avl_free( version ); |
209 | fclose( fp ); |
210 | if (verbose) printf( "BODY file read OK\n" ); |
211 | return 0; |
212 | |
213 | error: |
214 | avl_free( line.line ); |
215 | avl_free( string ); |
216 | avl_free( version ); |
217 | fclose( fp ); |
218 | avlFree_BODY(body); |
219 | return -1; |
220 | } |
221 | |
222 | |
223 | |
224 | void avlInit_BODY( avlBody *body ) |
225 | { |
226 | if (body == NULL) return; |
227 | body->body = NULL; |
228 | body->nbody = 0; |
229 | body->Sref = body->Bref = body->Cref = 0; |
230 | body->Xref = body->Yref = body->Zref = 0; |
231 | } |
232 | |
233 | |
234 | |
235 | void avlFree_BODY( avlBody *body ) |
236 | { |
237 | int i; |
238 | if (body == NULL) return; |
239 | for (i = 0; i < body->nbody; i++) |
240 | avl_free(body->body[i].name); |
241 | avl_free(body->body); |
242 | avlInit_BODY(body); |
243 | } |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | #ifndef AVL_MRF_INTERNAL |
22 | #error "This header is only intended for avlmrf internal use" |
23 | #endif |
24 | |
25 | #include <stdio.h> |
26 | #include <stdlib.h> |
27 | #include <string.h> |
28 | #include <stdbool.h> |
29 | |
30 | typedef struct |
31 | { |
32 | char *line; |
33 | size_t linesize; |
34 | } avlLineBuffer; |
35 | |
36 | |
37 | static |
38 | void avl_free( void *ptr ) |
39 | { |
40 | if (ptr == NULL) return; |
41 | free(ptr); |
42 | } |
43 | |
44 | |
45 | static |
46 | char* chop_newline( char *line ) |
47 | { |
48 | int len; |
49 | char *ptr; |
50 | if (line == NULL) return NULL; |
51 | ptr = strchr(line, '\n'); |
52 | if (ptr != NULL) *ptr = '\0'; |
53 | while ((len = strlen(line)) > 0 && line[len-1] == ' ') line[len-1] = '\0'; |
54 | return line; |
55 | } |
56 | |
57 | static |
58 | bool getLine_line( FILE *fp, avlLineBuffer *line ) |
59 | { |
60 | bool success = false; |
61 | |
62 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
63 | if (readsize > 0) |
| |
| |
64 | { |
65 | success = true; |
66 | } |
67 | else |
68 | { |
69 | printf( "ERROR on read in %s\n", __func__ ); |
70 | } |
71 | |
72 | return success; |
| 34 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
| 82 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
73 | } |
74 | |
75 | static |
76 | bool getLine_int1( FILE *fp, const char *msg, avlLineBuffer *line, int *val1 ) |
77 | { |
78 | bool success = false; |
79 | |
80 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
81 | if (readsize > 0) |
| |
82 | { |
83 | size_t nread = sscanf( line->line, "%d", val1 ); |
84 | if (nread == 1) |
| 56 | | Assuming 'nread' is equal to 1 | |
|
| |
85 | { |
86 | success = true; |
87 | } |
88 | else |
89 | { |
90 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
91 | } |
92 | } |
93 | |
94 | return success; |
| 58 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
95 | } |
96 | |
97 | static |
98 | bool getLine_int2( FILE *fp, const char *msg, avlLineBuffer *line, int *val1, int *val2 ) |
99 | { |
100 | bool success = false; |
101 | |
102 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
103 | if (readsize > 0) |
104 | { |
105 | size_t nread = sscanf( line->line, "%d %d", val1, val2 ); |
106 | if (nread == 2) |
107 | { |
108 | success = true; |
109 | } |
110 | else |
111 | { |
112 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
113 | } |
114 | } |
115 | |
116 | return success; |
117 | } |
118 | |
119 | static |
120 | bool getLine_int3( FILE *fp, const char *msg, avlLineBuffer *line, int *val1, int *val2, int *val3 ) |
121 | { |
122 | bool success = false; |
123 | |
124 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
125 | if (readsize > 0) |
126 | { |
127 | size_t nread = sscanf( line->line, "%d %d %d", val1, val2, val3 ); |
128 | if (nread == 3) |
129 | { |
130 | success = true; |
131 | } |
132 | else |
133 | { |
134 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
135 | } |
136 | } |
137 | |
138 | return success; |
139 | } |
140 | |
141 | static |
142 | bool getLine_int4( FILE *fp, const char *msg, avlLineBuffer *line, int *val1, int *val2, int *val3, int *val4 ) |
143 | { |
144 | bool success = false; |
145 | |
146 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
147 | if (readsize > 0) |
148 | { |
149 | size_t nread = sscanf( line->line, "%d %d %d %d", val1, val2, val3, val4 ); |
150 | if (nread == 4) |
151 | { |
152 | success = true; |
153 | } |
154 | else |
155 | { |
156 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
157 | } |
158 | } |
159 | |
160 | return success; |
161 | } |
162 | |
163 | static |
164 | bool getLine_intn( FILE *fp, const char *msg, avlLineBuffer *line, int *valn, int nn ) |
165 | { |
166 | |
167 | int n; |
168 | bool success = false; |
169 | |
170 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
171 | |
172 | if (readsize > 0) |
173 | { |
174 | char *ws = " "; |
175 | char *token = NULL; |
176 | size_t nread = 0; |
177 | |
178 | token = strtok( line->line, ws ); |
179 | if (token == NULL) goto error; |
180 | nread = sscanf( token, "%d", &(valn[0]) ); |
181 | if (nread == 1) |
182 | { |
183 | for (n = 1; n < nn; n++) |
184 | { |
185 | token = strtok( NULL, ws ); |
186 | if (token == NULL) goto error; |
187 | nread += sscanf( token, "%d", &(valn[n]) ); |
188 | } |
189 | if (nread == nn) |
190 | { |
191 | success = true; |
192 | } |
193 | else |
194 | { |
195 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
196 | } |
197 | } |
198 | else |
199 | { |
200 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
201 | } |
202 | } |
203 | |
204 | return success; |
205 | error: |
206 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
207 | return false; |
208 | } |
209 | |
210 | static |
211 | bool getLine_real1( FILE *fp, const char *msg, avlLineBuffer *line, double *val1 ) |
212 | { |
213 | bool success = false; |
214 | |
215 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
216 | if (readsize > 0) |
217 | { |
218 | size_t nread = sscanf( line->line, "%lf", val1 ); |
219 | if (nread == 1) |
220 | { |
221 | success = true; |
222 | } |
223 | else |
224 | { |
225 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
226 | } |
227 | } |
228 | |
229 | return success; |
230 | } |
231 | |
232 | static |
233 | bool getLine_real2( FILE *fp, const char *msg, avlLineBuffer *line, double *val1, double *val2 ) |
234 | { |
235 | bool success = false; |
236 | |
237 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
238 | if (readsize > 0) |
239 | { |
240 | size_t nread = sscanf( line->line, "%lf %lf", val1, val2 ); |
241 | if (nread == 2) |
242 | { |
243 | success = true; |
244 | } |
245 | else |
246 | { |
247 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
248 | } |
249 | } |
250 | |
251 | return success; |
252 | } |
253 | |
254 | static |
255 | bool getLine_real3( FILE *fp, const char *msg, avlLineBuffer *line, double *val1, double *val2, double *val3 ) |
256 | { |
257 | bool success = false; |
258 | |
259 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
260 | if (readsize > 0) |
| |
| |
261 | { |
262 | size_t nread = sscanf( line->line, "%lf %lf %lf", val1, val2, val3 ); |
263 | if (nread == 3) |
| 40 | | Assuming 'nread' is equal to 3 | |
|
| |
| 48 | | Assuming 'nread' is equal to 3 | |
|
| |
264 | { |
265 | success = true; |
266 | } |
267 | else |
268 | { |
269 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
270 | } |
271 | } |
272 | |
273 | return success; |
| 42 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
| 50 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
274 | } |
275 | |
276 | static |
277 | bool getLine_real4( FILE *fp, const char *msg, avlLineBuffer *line, double *val1, double *val2, double *val3, double *val4 ) |
278 | { |
279 | bool success = false; |
280 | |
281 | |
282 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
283 | if (readsize > 0) |
284 | { |
285 | size_t nread = sscanf( line->line, "%lf %lf %lf %lf", val1, val2, val3, val4 ); |
286 | if (nread == 4) |
287 | { |
288 | success = true; |
289 | } |
290 | else |
291 | { |
292 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
293 | } |
294 | } |
295 | |
296 | return success; |
297 | } |
298 | |
299 | static |
300 | bool getLine_realn( FILE *fp, const char *msg, avlLineBuffer *line, double *valn, int nn ) |
301 | { |
302 | |
303 | int n; |
304 | bool success = false; |
305 | char *ws = " "; |
306 | char *token; |
307 | size_t nread = 0; |
308 | |
309 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
310 | if (readsize > 0) |
311 | { |
312 | |
313 | token = strtok( line->line, ws ); |
314 | if (token == NULL) goto error; |
315 | nread = sscanf( token, "%lf", &(valn[0]) ); |
316 | if (nread == 1) |
317 | { |
318 | for (n = 1; n < nn; n++) |
319 | { |
320 | token = strtok( NULL, ws ); |
321 | if (token == NULL) goto error; |
322 | nread += sscanf( token, "%lf", &(valn[n]) ); |
323 | } |
324 | if (nread == nn) |
325 | { |
326 | success = true; |
327 | } |
328 | else |
329 | { |
330 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
331 | } |
332 | } |
333 | else |
334 | { |
335 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
336 | } |
337 | } |
338 | |
339 | return success; |
340 | error: |
341 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
342 | return false; |
343 | } |
344 | |
345 | static |
346 | bool getLine_string1( FILE *fp, const char *msg, avlLineBuffer *line, char *string1 ) |
347 | { |
348 | bool success = false; |
349 | |
350 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
351 | if (readsize > 0) |
| |
| |
352 | { |
353 | size_t nread = sscanf( line->line, "%s", string1 ); |
354 | if (nread == 1) |
| 11 | | Assuming 'nread' is equal to 1 | |
|
| |
| 72 | | Assuming 'nread' is equal to 1 | |
|
| |
355 | { |
356 | success = true; |
357 | } |
358 | else |
359 | { |
360 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
361 | } |
362 | } |
363 | |
364 | return success; |
| 13 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
| 74 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
365 | } |
366 | |
367 | static |
368 | bool getLine_string2( FILE *fp, const char *msg, avlLineBuffer *line, char *string1, char *string2 ) |
369 | { |
370 | bool success = false; |
371 | |
372 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
373 | if (readsize > 0) |
| |
374 | { |
375 | size_t nread = sscanf( line->line, "%s %s", string1, string2 ); |
376 | if (nread == 2) |
| 22 | | Assuming 'nread' is equal to 2 | |
|
| |
377 | { |
378 | success = true; |
379 | } |
380 | else |
381 | { |
382 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
383 | } |
384 | } |
385 | |
386 | return success; |
| 24 | | Returning the value 1 (loaded from 'success'), which participates in a condition later | |
|
387 | } |
388 | |
389 | static |
390 | bool getLine_real1_string1( FILE *fp, const char *msg, avlLineBuffer *line, double *val1, char *string1 ) |
391 | { |
392 | bool success = false; |
393 | |
394 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
395 | if (readsize > 0) |
396 | { |
397 | size_t nread = sscanf( line->line, "%lf %s", val1, string1 ); |
398 | if (nread == 2) |
399 | { |
400 | success = true; |
401 | } |
402 | else |
403 | { |
404 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
405 | } |
406 | } |
407 | |
408 | return success; |
409 | } |
410 | |
411 | static |
412 | bool getLine_int1_realn( FILE *fp, const char *msg, avlLineBuffer *line, int *val1, double *valn, int nn ) |
413 | { |
414 | int n; |
415 | bool success = false; |
416 | char *ws = " "; |
417 | char *token; |
418 | size_t nread; |
419 | |
420 | size_t readsize = getline( &line->line, &line->linesize, fp ); |
421 | if (readsize > 0) |
422 | { |
423 | token = strtok( line->line, ws ); |
424 | if (token == NULL) goto error; |
425 | nread = sscanf( token, "%d", val1 ); |
426 | if (nread == 1) |
427 | { |
428 | for (n = 0; n < nn; n++) |
429 | { |
430 | token = strtok( NULL, ws ); |
431 | if (token == NULL) goto error; |
432 | nread += sscanf( token, "%lf", &(valn[n]) ); |
433 | } |
434 | if (nread == nn+1) |
435 | { |
436 | success = true; |
437 | } |
438 | else |
439 | { |
440 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
441 | } |
442 | } |
443 | else |
444 | { |
445 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
446 | } |
447 | } |
448 | |
449 | return success; |
450 | error: |
451 | printf( "ERROR: expected %s; got %s\n", msg, line->line ); |
452 | return false; |
453 | } |