summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2000-09-15 08:10:33 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2000-09-15 08:10:33 (GMT)
commit2af72d5d6d25949bcdeb03dd38d9f8753f33d6b5 (patch)
tree7e3201190044826b5022aa3f1c0d51995d80a888 /Modules
parent0bb44a4a3a98b7bd73ff0f34d872ddcc9556e393 (diff)
downloadcpython-2af72d5d6d25949bcdeb03dd38d9f8753f33d6b5.zip
cpython-2af72d5d6d25949bcdeb03dd38d9f8753f33d6b5.tar.gz
cpython-2af72d5d6d25949bcdeb03dd38d9f8753f33d6b5.tar.bz2
Use symbolic constants for allowable short ranges.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/structmodule.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/structmodule.c b/Modules/structmodule.c
index 1b38c67..4d60122 100644
--- a/Modules/structmodule.c
+++ b/Modules/structmodule.c
@@ -66,6 +66,8 @@ typedef struct { char c; void *x; } s_void_p;
#define DOUBLE_ALIGN (sizeof(s_double) - sizeof(double))
#define VOID_P_ALIGN (sizeof(s_void_p) - sizeof(void *))
+#define STRINGIFY(x) #x
+
#ifdef __powerc
#pragma options align=reset
#endif
@@ -519,9 +521,10 @@ np_short(char *p, PyObject *v, const formatdef *f)
long x;
if (get_long(v, &x) < 0)
return -1;
- if (x < -32768 || x > 32767){
+ if (x < SHRT_MIN || x > SHRT_MAX){
PyErr_SetString(StructError,
- "short format requires -32768<=number<=32767");
+ "short format requires " STRINGIFY(SHRT_MIN)
+ "<=number<=" STRINGIFY(SHRT_MAX));
return -1;
}
* (short *)p = (short)x;
@@ -534,9 +537,9 @@ np_ushort(char *p, PyObject *v, const formatdef *f)
long x;
if (get_long(v, &x) < 0)
return -1;
- if (x < 0 || x > 65535){
+ if (x < 0 || x > USHRT_MAX){
PyErr_SetString(StructError,
- "short format requires 0<=number<=65535");
+ "short format requires 0<=number<=" STRINGIFY(USHRT_MAX));
return -1;
}
* (unsigned short *)p = (unsigned short)x;