comparison Objects/stringlib/string_format.h @ 62168:26fac74ebab3 legacy-trunk

correctly overflow when indexes are too large
author Benjamin Peterson <benjamin@python.org>
date Mon, 07 Jun 2010 22:23:23 +0000
parents fd25030223b0
children b36cb4602e21
comparison
equal deleted inserted replaced
62165:f5ce5e1bb23a 62168:26fac74ebab3
371 case '[': 371 case '[':
372 *is_attribute = 0; 372 *is_attribute = 0;
373 if (_FieldNameIterator_item(self, name) == 0) 373 if (_FieldNameIterator_item(self, name) == 0)
374 return 0; 374 return 0;
375 *name_idx = get_integer(name); 375 *name_idx = get_integer(name);
376 if (*name_idx == -1 && PyErr_Occurred())
377 return 0;
376 break; 378 break;
377 default: 379 default:
378 /* Invalid character follows ']' */ 380 /* Invalid character follows ']' */
379 PyErr_SetString(PyExc_ValueError, "Only '.' or '[' may " 381 PyErr_SetString(PyExc_ValueError, "Only '.' or '[' may "
380 "follow ']' in format field specifier"); 382 "follow ']' in format field specifier");
427 SubString_init(first, ptr, p - ptr); 429 SubString_init(first, ptr, p - ptr);
428 FieldNameIterator_init(rest, p, end - p); 430 FieldNameIterator_init(rest, p, end - p);
429 431
430 /* see if "first" is an integer, in which case it's used as an index */ 432 /* see if "first" is an integer, in which case it's used as an index */
431 *first_idx = get_integer(first); 433 *first_idx = get_integer(first);
434 if (*first_idx == -1 && PyErr_Occurred())
435 return 0;
432 436
433 field_name_is_empty = first->ptr >= first->end; 437 field_name_is_empty = first->ptr >= first->end;
434 438
435 /* If the field name is omitted or if we have a numeric index 439 /* If the field name is omitted or if we have a numeric index
436 specified, then we're doing numeric indexing into args. */ 440 specified, then we're doing numeric indexing into args. */