OLD | NEW |
1 /* Parse a printf-style format string. | 1 /* Parse a printf-style format string. |
2 | 2 |
3 Copyright (C) 1986-2012 Free Software Foundation, Inc. | 3 Copyright (C) 1986-2013 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #ifdef GDBSERVER | 20 #ifdef GDBSERVER |
21 #include "server.h" | 21 #include "server.h" |
22 #else | 22 #else |
23 #include "defs.h" | 23 #include "defs.h" |
24 #endif | 24 #endif |
25 | 25 |
26 #include <string.h> | 26 #include <string.h> |
27 | 27 |
28 #include "format.h" | 28 #include "format.h" |
29 | 29 |
30 struct format_piece * | 30 struct format_piece * |
31 parse_format_string (char **arg) | 31 parse_format_string (const char **arg) |
32 { | 32 { |
33 char *s, *f, *string; | 33 const char *s; |
34 char *prev_start; | 34 char *f, *string; |
35 char *percent_loc; | 35 const char *prev_start; |
| 36 const char *percent_loc; |
36 char *sub_start, *current_substring; | 37 char *sub_start, *current_substring; |
37 struct format_piece *pieces; | 38 struct format_piece *pieces; |
38 int next_frag; | 39 int next_frag; |
39 int max_pieces; | 40 int max_pieces; |
40 enum argclass this_argclass; | 41 enum argclass this_argclass; |
41 | 42 |
42 s = *arg; | 43 s = *arg; |
43 | 44 |
44 /* Parse the format-control string and copy it into the string STRING, | 45 /* Parse the format-control string and copy it into the string STRING, |
45 processing some kinds of escape sequence. */ | 46 processing some kinds of escape sequence. */ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 percent_loc = f - 1; | 150 percent_loc = f - 1; |
150 | 151 |
151 /* Check the validity of the format specifier, and work | 152 /* Check the validity of the format specifier, and work |
152 out what argument it expects. We only accept C89 | 153 out what argument it expects. We only accept C89 |
153 format strings, with the exception of long long (which | 154 format strings, with the exception of long long (which |
154 we autoconf for). */ | 155 we autoconf for). */ |
155 | 156 |
156 /* The first part of a format specifier is a set of flag | 157 /* The first part of a format specifier is a set of flag |
157 characters. */ | 158 characters. */ |
158 » while (strchr ("0-+ #", *f)) | 159 » while (*f != '\0' && strchr ("0-+ #", *f)) |
159 { | 160 { |
160 if (*f == '#') | 161 if (*f == '#') |
161 seen_hash = 1; | 162 seen_hash = 1; |
162 else if (*f == '0') | 163 else if (*f == '0') |
163 seen_zero = 1; | 164 seen_zero = 1; |
164 else if (*f == ' ') | 165 else if (*f == ' ') |
165 seen_space = 1; | 166 seen_space = 1; |
166 else if (*f == '+') | 167 else if (*f == '+') |
167 seen_plus = 1; | 168 seen_plus = 1; |
168 f++; | 169 f++; |
169 } | 170 } |
170 | 171 |
171 /* The next part of a format specifier is a width. */ | 172 /* The next part of a format specifier is a width. */ |
172 » while (strchr ("0123456789", *f)) | 173 » while (*f != '\0' && strchr ("0123456789", *f)) |
173 f++; | 174 f++; |
174 | 175 |
175 /* The next part of a format specifier is a precision. */ | 176 /* The next part of a format specifier is a precision. */ |
176 if (*f == '.') | 177 if (*f == '.') |
177 { | 178 { |
178 seen_prec = 1; | 179 seen_prec = 1; |
179 f++; | 180 f++; |
180 » while (strchr ("0123456789", *f)) | 181 » while (*f != '\0' && strchr ("0123456789", *f)) |
181 f++; | 182 f++; |
182 } | 183 } |
183 | 184 |
184 /* The next part of a format specifier is a length modifier. */ | 185 /* The next part of a format specifier is a length modifier. */ |
185 if (*f == 'h') | 186 if (*f == 'h') |
186 { | 187 { |
187 seen_h = 1; | 188 seen_h = 1; |
188 f++; | 189 f++; |
189 } | 190 } |
190 else if (*f == 'l') | 191 else if (*f == 'l') |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 /* FALLTHROUGH */ | 239 /* FALLTHROUGH */ |
239 | 240 |
240 case 'd': | 241 case 'd': |
241 case 'i': | 242 case 'i': |
242 if (lcount == 0) | 243 if (lcount == 0) |
243 this_argclass = int_arg; | 244 this_argclass = int_arg; |
244 else if (lcount == 1) | 245 else if (lcount == 1) |
245 this_argclass = long_arg; | 246 this_argclass = long_arg; |
246 else | 247 else |
247 this_argclass = long_long_arg; | 248 this_argclass = long_long_arg; |
248 | 249 |
249 » if (seen_big_l) | 250 » if (seen_big_l) |
250 » bad = 1; | 251 » bad = 1; |
251 » break; | 252 » break; |
252 | 253 |
253 case 'c': | 254 case 'c': |
254 this_argclass = lcount == 0 ? int_arg : wide_char_arg; | 255 this_argclass = lcount == 0 ? int_arg : wide_char_arg; |
255 if (lcount > 1 || seen_h || seen_big_l) | 256 if (lcount > 1 || seen_h || seen_big_l) |
256 bad = 1; | 257 bad = 1; |
257 if (seen_prec || seen_zero || seen_space || seen_plus) | 258 if (seen_prec || seen_zero || seen_space || seen_plus) |
258 bad = 1; | 259 bad = 1; |
259 break; | 260 break; |
260 | 261 |
261 case 'p': | 262 case 'p': |
262 this_argclass = ptr_arg; | 263 this_argclass = ptr_arg; |
263 if (lcount || seen_h || seen_big_l) | 264 if (lcount || seen_h || seen_big_l) |
264 bad = 1; | 265 bad = 1; |
265 » if (seen_prec || seen_zero || seen_space || seen_plus) | 266 » if (seen_prec) |
| 267 » bad = 1; |
| 268 » if (seen_hash || seen_zero || seen_space || seen_plus) |
266 bad = 1; | 269 bad = 1; |
267 break; | 270 break; |
268 | 271 |
269 case 's': | 272 case 's': |
270 this_argclass = lcount == 0 ? string_arg : wide_string_arg; | 273 this_argclass = lcount == 0 ? string_arg : wide_string_arg; |
271 if (lcount > 1 || seen_h || seen_big_l) | 274 if (lcount > 1 || seen_h || seen_big_l) |
272 bad = 1; | 275 bad = 1; |
273 if (seen_zero || seen_space || seen_plus) | 276 if (seen_zero || seen_space || seen_plus) |
274 bad = 1; | 277 bad = 1; |
275 break; | 278 break; |
276 | 279 |
277 case 'e': | 280 case 'e': |
278 case 'f': | 281 case 'f': |
279 case 'g': | 282 case 'g': |
280 case 'E': | 283 case 'E': |
281 case 'G': | 284 case 'G': |
282 if (seen_big_h || seen_big_d || seen_double_big_d) | 285 if (seen_big_h || seen_big_d || seen_double_big_d) |
283 this_argclass = decfloat_arg; | 286 this_argclass = decfloat_arg; |
284 else if (seen_big_l) | 287 else if (seen_big_l) |
285 this_argclass = long_double_arg; | 288 this_argclass = long_double_arg; |
286 else | 289 else |
287 this_argclass = double_arg; | 290 this_argclass = double_arg; |
288 | 291 |
289 » if (lcount || seen_h) | 292 » if (lcount || seen_h) |
290 » bad = 1; | 293 » bad = 1; |
291 » break; | 294 » break; |
292 | 295 |
293 case '*': | 296 case '*': |
294 error (_("`*' not supported for precision or width in printf")); | 297 error (_("`*' not supported for precision or width in printf")); |
295 | 298 |
296 case 'n': | 299 case 'n': |
297 error (_("Format specifier `n' not supported in printf")); | 300 error (_("Format specifier `n' not supported in printf")); |
298 | 301 |
299 case '\0': | 302 case '\0': |
300 error (_("Incomplete format specifier at end of format string")); | 303 error (_("Incomplete format specifier at end of format string")); |
301 | 304 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if (location == NULL) | 394 if (location == NULL) |
392 return; | 395 return; |
393 | 396 |
394 if (*location != NULL) | 397 if (*location != NULL) |
395 { | 398 { |
396 free_format_pieces (*location); | 399 free_format_pieces (*location); |
397 *location = NULL; | 400 *location = NULL; |
398 } | 401 } |
399 } | 402 } |
400 | 403 |
OLD | NEW |