comparison Python/getargs.c @ 68794:d9633064458c 3.1

Issue #8651: PyArg_Parse*() functions raise an OverflowError if the file doesn't have PY_SSIZE_T_CLEAN define and the size doesn't fit in an int (length bigger than 2^31-1 bytes).
author Victor Stinner <victor.stinner@haypocalc.com>
date Mon, 21 Mar 2011 03:22:50 +0100
parents 13b2a592c186
children 18f7fe1d2108
comparison
equal deleted inserted replaced
68790:51ab840346fe 68794:d9633064458c
611 { 611 {
612 /* For # codes */ 612 /* For # codes */
613 #define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\ 613 #define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\
614 if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \ 614 if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
615 else q=va_arg(*p_va, int*); 615 else q=va_arg(*p_va, int*);
616 #define STORE_SIZE(s) if (flags & FLAG_SIZE_T) *q2=s; else *q=s; 616 #define STORE_SIZE(s) \
617 if (flags & FLAG_SIZE_T) \
618 *q2=s; \
619 else { \
620 if (INT_MAX < s) { \
621 PyErr_SetString(PyExc_OverflowError, \
622 "size does not fit in an int"); \
623 return converterr("", arg, msgbuf, bufsize); \
624 } \
625 *q=s; \
626 }
617 #define BUFFER_LEN ((flags & FLAG_SIZE_T) ? *q2:*q) 627 #define BUFFER_LEN ((flags & FLAG_SIZE_T) ? *q2:*q)
618 628
619 const char *format = *p_format; 629 const char *format = *p_format;
620 char c = *format++; 630 char c = *format++;
621 PyObject *uarg; 631 PyObject *uarg;