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

Skip to content

Commit 601b963

Browse files
committed
- Fixing annoying warnings.
1 parent a6e436e commit 601b963

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Modules/_sre.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,21 @@ static char sre_char_lower[128] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
146146

147147
static unsigned int sre_lower(unsigned int ch)
148148
{
149-
return ((ch) < 128 ? sre_char_lower[ch] : ch);
149+
return ((ch) < 128 ? (unsigned int)sre_char_lower[ch] : ch);
150150
}
151151

152152
/* locale-specific character predicates */
153-
154-
#define SRE_LOC_IS_DIGIT(ch) ((ch) < 256 ? isdigit((ch)) : 0)
155-
#define SRE_LOC_IS_SPACE(ch) ((ch) < 256 ? isspace((ch)) : 0)
153+
/* !(c & ~N) == (c < N+1) for any unsigned c, this avoids
154+
* warnings when c's type supports only numbers < N+1 */
155+
#define SRE_LOC_IS_DIGIT(ch) (!((ch) & ~255) ? isdigit((ch)) : 0)
156+
#define SRE_LOC_IS_SPACE(ch) (!((ch) & ~255) ? isspace((ch)) : 0)
156157
#define SRE_LOC_IS_LINEBREAK(ch) ((ch) == '\n')
157-
#define SRE_LOC_IS_ALNUM(ch) ((ch) < 256 ? isalnum((ch)) : 0)
158+
#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? isalnum((ch)) : 0)
158159
#define SRE_LOC_IS_WORD(ch) (SRE_LOC_IS_ALNUM((ch)) || (ch) == '_')
159160

160161
static unsigned int sre_lower_locale(unsigned int ch)
161162
{
162-
return ((ch) < 256 ? tolower((ch)) : ch);
163+
return ((ch) < 256 ? (unsigned int)tolower((ch)) : ch);
163164
}
164165

165166
/* unicode-specific character predicates */
@@ -484,7 +485,9 @@ SRE_CHARSET(SRE_CODE* set, SRE_CODE ch)
484485
set += count*16;
485486
}
486487
else {
487-
if (ch < 65536)
488+
/* !(c & ~N) == (c < N+1) for any unsigned c, this avoids
489+
* warnings when c's type supports only numbers < N+1 */
490+
if (!(ch & ~65535))
488491
block = ((unsigned char*)set)[ch >> 8];
489492
else
490493
block = -1;

Modules/sre.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ typedef struct {
7676
void* mark[SRE_MARK_SIZE];
7777
/* dynamically allocated stuff */
7878
char* data_stack;
79-
int data_stack_size;
80-
int data_stack_base;
79+
unsigned int data_stack_size;
80+
unsigned int data_stack_base;
8181
/* current repeat context */
8282
SRE_REPEAT *repeat;
8383
/* hooks */

0 commit comments

Comments
 (0)