Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2af72d5

Browse files
committed
Use symbolic constants for allowable short ranges.
1 parent 0bb44a4 commit 2af72d5

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Modules/structmodule.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ typedef struct { char c; void *x; } s_void_p;
6666
#define DOUBLE_ALIGN (sizeof(s_double) - sizeof(double))
6767
#define VOID_P_ALIGN (sizeof(s_void_p) - sizeof(void *))
6868

69+
#define STRINGIFY(x) #x
70+
6971
#ifdef __powerc
7072
#pragma options align=reset
7173
#endif
@@ -519,9 +521,10 @@ np_short(char *p, PyObject *v, const formatdef *f)
519521
long x;
520522
if (get_long(v, &x) < 0)
521523
return -1;
522-
if (x < -32768 || x > 32767){
524+
if (x < SHRT_MIN || x > SHRT_MAX){
523525
PyErr_SetString(StructError,
524-
"short format requires -32768<=number<=32767");
526+
"short format requires " STRINGIFY(SHRT_MIN)
527+
"<=number<=" STRINGIFY(SHRT_MAX));
525528
return -1;
526529
}
527530
* (short *)p = (short)x;
@@ -534,9 +537,9 @@ np_ushort(char *p, PyObject *v, const formatdef *f)
534537
long x;
535538
if (get_long(v, &x) < 0)
536539
return -1;
537-
if (x < 0 || x > 65535){
540+
if (x < 0 || x > USHRT_MAX){
538541
PyErr_SetString(StructError,
539-
"short format requires 0<=number<=65535");
542+
"short format requires 0<=number<=" STRINGIFY(USHRT_MAX));
540543
return -1;
541544
}
542545
* (unsigned short *)p = (unsigned short)x;

0 commit comments

Comments
 (0)