summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-05-09 21:50:00 (GMT)
committerFred Drake <fdrake@acm.org>2000-05-09 21:50:00 (GMT)
commit230cae7474858a8ce2147849a7a00a5501564641 (patch)
tree98360cfa478c5ec40938cc76d2791848ca37e966 /Python/getargs.c
parenta69ef82643c362ba7c2d9e08eaa02fc0a997f829 (diff)
downloadcpython-230cae7474858a8ce2147849a7a00a5501564641.zip
cpython-230cae7474858a8ce2147849a7a00a5501564641.tar.gz
cpython-230cae7474858a8ce2147849a7a00a5501564641.tar.bz2
Trent Mick <trentm@activestate.com>:
Limit the 'b' formatter of PyArg_ParseTuple to valid values of an unsigned char, i.e. [0,UCHAR_MAX]. It is expected that this is the common usage of 'b'. An OverflowError is raised if the parsed value is outside this range.
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index f949da8..69ef167 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -465,28 +465,28 @@ convertsimple1(arg, p_format, p_va)
switch (c) {
- case 'b': /* byte -- very short int */
+ case 'b': /* unsigned byte -- very short int */
{
char *p = va_arg(*p_va, char *);
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<b>";
- else if (ival < CHAR_MIN) {
+ else if (ival < 0) {
PyErr_SetString(PyExc_OverflowError,
- "byte integer is less than minimum");
+ "unsigned byte integer is less than minimum");
return "integer<b>";
}
- else if (ival > CHAR_MAX && ival >= 256) {
+ else if (ival > UCHAR_MAX) {
PyErr_SetString(PyExc_OverflowError,
- "byte integer is greater than maximum");
+ "unsigned byte integer is greater than maximum");
return "integer<b>";
}
else
- *p = (char) ival;
+ *p = (unsigned char) ival;
break;
}
- case 'h': /* short int */
+ case 'h': /* signed short int */
{
short *p = va_arg(*p_va, short *);
long ival = PyInt_AsLong(arg);
@@ -494,12 +494,12 @@ convertsimple1(arg, p_format, p_va)
return "integer<h>";
else if (ival < SHRT_MIN) {
PyErr_SetString(PyExc_OverflowError,
- "short integer is less than minimum");
+ "signed short integer is less than minimum");
return "integer<h>";
}
else if (ival > SHRT_MAX) {
PyErr_SetString(PyExc_OverflowError,
- "short integer is greater than maximum");
+ "signed short integer is greater than maximum");
return "integer<h>";
}
else
@@ -507,7 +507,7 @@ convertsimple1(arg, p_format, p_va)
break;
}
- case 'i': /* int */
+ case 'i': /* signed int */
{
int *p = va_arg(*p_va, int *);
long ival = PyInt_AsLong(arg);
@@ -515,12 +515,12 @@ convertsimple1(arg, p_format, p_va)
return "integer<i>";
else if (ival < INT_MIN) {
PyErr_SetString(PyExc_OverflowError,
- "integer is less than minimum");
+ "signed integer is less than minimum");
return "integer<i>";
}
else if (ival > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
- "integer is greater than maximum");
+ "signed integer is greater than maximum");
return "integer<i>";
}
else