Be more permissive when validating format string arguments.
Previously, the code would assert if the caller passed too many arguments to wxPrintf() or other printf-like functions. But that can happen legitimately in translations: in some languages such as Hebrew, using "1" (i.e. "%d") in the singular feels unnatural and it's better to use the word "one" and left the variadic argument unused. Relax the check not to assert in this case. This is consistent with the standard library and other implementations. Notice that gettext's msgfmt doesn't complain about this case either in the specific case of singular forms. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76027 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9adba53251
commit
c7972da951
@ -155,6 +155,9 @@ public:
|
||||
// a char* string is also a pointer and an integer is also a char.
|
||||
enum ArgumentType
|
||||
{
|
||||
Arg_Unused = 0, // not used at all; the value of 0 is chosen to
|
||||
// conveniently pass wxASSERT_ARG_TYPE's check
|
||||
|
||||
Arg_Char = 0x0001, // character as char %c
|
||||
Arg_Pointer = 0x0002, // %p
|
||||
Arg_String = 0x0004 | Arg_Pointer, // any form of string (%s and %p too)
|
||||
|
@ -654,8 +654,17 @@ wxFormatString::ArgumentType DoGetArgumentType(const CharType *format,
|
||||
|
||||
wxPrintfConvSpecParser<CharType> parser(format);
|
||||
|
||||
wxCHECK_MSG( n <= parser.nargs, wxFormatString::Arg_Unknown,
|
||||
"more arguments than format string specifiers?" );
|
||||
if ( n > parser.nargs )
|
||||
{
|
||||
// The n-th argument doesn't appear in the format string and is unused.
|
||||
// This can happen e.g. if a translation of the format string is used
|
||||
// and the translation language tends to avoid numbers in singular forms.
|
||||
// The translator would then typically replace "%d" with "One" (e.g. in
|
||||
// Hebrew). Passing too many vararg arguments does not harm, so its
|
||||
// better to be more permissive here and allow legitimate uses in favour
|
||||
// of catching harmless errors.
|
||||
return wxFormatString::Arg_Unused;
|
||||
}
|
||||
|
||||
wxCHECK_MSG( parser.pspec[n-1] != NULL, wxFormatString::Arg_Unknown,
|
||||
"requested argument not found - invalid format string?" );
|
||||
|
Loading…
Reference in New Issue
Block a user