Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit082c0df

Browse files
committed
Fix some wide-character bugs in the text-search parser.
In p_isdigit and other character class test functions generated by thep_iswhat macro, the code path for non-C locales with multibyte encodingscontained a bogus pointer cast that would accidentally fail to malfunctionif types wchar_t and wint_t have the same width. Apparently that is trueon most platforms, but not on recent Cygwin releases. Remove the cast,as it seems completely unnecessary (I think it arose from a false analogyto the need to cast to unsigned char when dealing with the <ctype.h>functions). Per bug #8970 from Marco Atzeri.In the same functions, the code path for C locale with a multibyte encodingsimply ANDed each wide character with 0xFF before passing it to thecorresponding <ctype.h> function. This could result in false positiveanswers for some non-ASCII characters, so use a range test instead.Noted by me while investigating Marco's complaint.Also, remove some useless though not actually buggy maskings and castsin the hand-coded p_isalnum and p_isalpha functions, which evidentlygot tested a bit more carefully than the macro-generated functions.
1 parentc8158a2 commit082c0df

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

‎src/backend/tsearch/wparser_def.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ TParserCopyClose(TParser *prs)
432432
* or give wrong result.
433433
*- multibyte encoding and C-locale often are used for
434434
* Asian languages.
435-
*- if locale is Cthe we use pgwstr instead of wstr
435+
*- if locale is Cthen we use pgwstr instead of wstr.
436436
*/
437437

438438
#ifdefUSE_WIDE_UPPER_LOWER
@@ -444,9 +444,13 @@ p_is##type(TParser *prs) {\
444444
if ( prs->usewide )\
445445
{\
446446
if ( prs->pgwstr )\
447-
return is##type( 0xff & *( prs->pgwstr + prs->state->poschar) );\
448-
\
449-
return isw##type( *(wint_t*)( prs->wstr + prs->state->poschar ) );\
447+
{\
448+
unsigned int c = *(prs->pgwstr + prs->state->poschar);\
449+
if ( c > 0x7f )\
450+
return 0;\
451+
return is##type( c );\
452+
}\
453+
return isw##type( *( prs->wstr + prs->state->poschar ) );\
450454
}\
451455
\
452456
return is##type( *(unsigned char*)( prs->str + prs->state->posbyte ) ); \
@@ -475,10 +479,10 @@ p_isalnum(TParser *prs)
475479
if (c>0x7f)
476480
return1;
477481

478-
returnisalnum(0xff&c);
482+
returnisalnum(c);
479483
}
480484

481-
returniswalnum((wint_t)*(prs->wstr+prs->state->poschar));
485+
returniswalnum(*(prs->wstr+prs->state->poschar));
482486
}
483487

484488
returnisalnum(*(unsignedchar*) (prs->str+prs->state->posbyte));
@@ -507,10 +511,10 @@ p_isalpha(TParser *prs)
507511
if (c>0x7f)
508512
return1;
509513

510-
returnisalpha(0xff&c);
514+
returnisalpha(c);
511515
}
512516

513-
returniswalpha((wint_t)*(prs->wstr+prs->state->poschar));
517+
returniswalpha(*(prs->wstr+prs->state->poschar));
514518
}
515519

516520
returnisalpha(*(unsignedchar*) (prs->str+prs->state->posbyte));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp