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

Commit3c7b4ef

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 parentcfebd60 commit3c7b4ef

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
@@ -426,7 +426,7 @@ TParserCopyClose(TParser *prs)
426426
* or give wrong result.
427427
* - multibyte encoding and C-locale often are used for
428428
* Asian languages.
429-
* - if locale is Cthe we use pgwstr instead of wstr
429+
* - if locale is Cthen we use pgwstr instead of wstr.
430430
*/
431431

432432
#ifdefUSE_WIDE_UPPER_LOWER
@@ -438,9 +438,13 @@ p_is##type(TParser *prs) {\
438438
if ( prs->usewide )\
439439
{\
440440
if ( prs->pgwstr )\
441-
return is##type( 0xff & *( prs->pgwstr + prs->state->poschar) );\
442-
\
443-
return isw##type( *(wint_t*)( prs->wstr + prs->state->poschar ) );\
441+
{\
442+
unsigned int c = *(prs->pgwstr + prs->state->poschar);\
443+
if ( c > 0x7f )\
444+
return 0;\
445+
return is##type( c );\
446+
}\
447+
return isw##type( *( prs->wstr + prs->state->poschar ) );\
444448
}\
445449
\
446450
return is##type( *(unsigned char*)( prs->str + prs->state->posbyte ) ); \
@@ -469,10 +473,10 @@ p_isalnum(TParser *prs)
469473
if (c>0x7f)
470474
return1;
471475

472-
returnisalnum(0xff&c);
476+
returnisalnum(c);
473477
}
474478

475-
returniswalnum((wint_t)*(prs->wstr+prs->state->poschar));
479+
returniswalnum(*(prs->wstr+prs->state->poschar));
476480
}
477481

478482
returnisalnum(*(unsignedchar*) (prs->str+prs->state->posbyte));
@@ -501,10 +505,10 @@ p_isalpha(TParser *prs)
501505
if (c>0x7f)
502506
return1;
503507

504-
returnisalpha(0xff&c);
508+
returnisalpha(c);
505509
}
506510

507-
returniswalpha((wint_t)*(prs->wstr+prs->state->poschar));
511+
returniswalpha(*(prs->wstr+prs->state->poschar));
508512
}
509513

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp