Changeset 177825 in webkit


Ignore:
Timestamp:
Dec 30, 2014 12:43:00 PM (9 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] Enable the compiler to check format strings specified with UI_STRING and UI_STRING_KEY
https://bugs.webkit.org/show_bug.cgi?id=140003

Reviewed by Darin Adler.

  • Misc/WebLocalizableStrings.h: Made UI_STRING and UI_STRING_KEY call a new helper function

that takes their "string" parameter as a "value" "parameter and has an attribute telling
the compiler that if the "value" parameter is a format string then the function returns a
modified version of it. The result is that if UI_STRING is used as a format string parameter
to some function or method, the compiler will check the format specifiers in the string
against the other parameters.

Location:
trunk/Source/WebKit/mac
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/mac/ChangeLog

    r177817 r177825  
     12014-12-30  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Enable the compiler to check format strings specified with UI_STRING and UI_STRING_KEY
     4        https://bugs.webkit.org/show_bug.cgi?id=140003
     5
     6        Reviewed by Darin Adler.
     7
     8        * Misc/WebLocalizableStrings.h: Made UI_STRING and UI_STRING_KEY call a new helper function
     9        that takes their "string" parameter as a "value" "parameter and has an attribute telling
     10        the compiler that if the "value" parameter is a format string then the function returns a
     11        modified version of it. The result is that if UI_STRING is used as a format string parameter
     12        to some function or method, the compiler will check the format specifiers in the string
     13        against the other parameters.
     14
    1152014-12-29  Dan Bernstein  <mitz@apple.com>
    216
  • trunk/Source/WebKit/mac/Misc/WebLocalizableStrings.h

    r165676 r177825  
    2929#if __OBJC__
    3030@class NSBundle;
    31 #elif __cplusplus
     31typedef NSString *WebLocalizedStringType;
     32#else
     33#if __cplusplus
    3234class NSBundle;
    3335#else
    3436typedef struct NSBundle NSBundle;
     37#endif
     38typedef CFStringRef WebLocalizedStringType;
    3539#endif
    3640
     
    4448#endif
    4549
    46 #if __OBJC__
    47 NSString *WebLocalizedString(WebLocalizableStringsBundle *bundle, const char *key);
    48 #else
    49 CFStringRef WebLocalizedString(WebLocalizableStringsBundle *bundle, const char *key);
    50 #endif
     50WebLocalizedStringType WebLocalizedString(WebLocalizableStringsBundle* bundle, const char* key);
    5151
    5252#if TARGET_OS_IPHONE
     
    5858#endif
    5959
     60static inline __attribute__((format_arg(3))) WebLocalizedStringType WebLocalizedStringWithValue(WebLocalizableStringsBundle* bundle, const char* key, const char* value)
     61{
     62    return WebLocalizedString(bundle, key);
     63}
     64
    6065#ifdef FRAMEWORK_NAME
    6166
     
    6469extern WebLocalizableStringsBundle LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME);
    6570
    66 #define UI_STRING(string, comment) WebLocalizedString(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), string)
    67 #define UI_STRING_KEY(string, key, comment) WebLocalizedString(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), key)
     71#define UI_STRING(string, comment) WebLocalizedStringWithValue(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), string, string)
     72#define UI_STRING_KEY(string, key, comment) WebLocalizedStringWithValue(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), key, string)
    6873
    6974#else
    7075
    71 #define UI_STRING(string, comment) WebLocalizedString(0, string)
    72 #define UI_STRING_KEY(string, key, comment) WebLocalizedString(0, key)
     76#define UI_STRING(string, comment) WebLocalizedStringWithValue(0, string, string)
     77#define UI_STRING_KEY(string, key, comment) WebLocalizedStringWithValue(0, key, string)
    7378
    7479#endif
Note: See TracChangeset for help on using the changeset viewer.