security/sandbox/chromium/base/strings/string_util_stripped.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #include <wchar.h>
     3 namespace base {
     5 bool IsWprintfFormatPortable(const wchar_t* format) {
     6   for (const wchar_t* position = format; *position != '\0'; ++position) {
     7     if (*position == '%') {
     8       bool in_specification = true;
     9       bool modifier_l = false;
    10       while (in_specification) {
    11         // Eat up characters until reaching a known specifier.
    12         if (*++position == '\0') {
    13           // The format string ended in the middle of a specification.  Call
    14           // it portable because no unportable specifications were found.  The
    15           // string is equally broken on all platforms.
    16           return true;
    17         }
    19         if (*position == 'l') {
    20           // 'l' is the only thing that can save the 's' and 'c' specifiers.
    21           modifier_l = true;
    22         } else if (((*position == 's' || *position == 'c') && !modifier_l) ||
    23                    *position == 'S' || *position == 'C' || *position == 'F' ||
    24                    *position == 'D' || *position == 'O' || *position == 'U') {
    25           // Not portable.
    26           return false;
    27         }
    29         if (wcschr(L"diouxXeEfgGaAcspn%", *position)) {
    30           // Portable, keep scanning the rest of the format string.
    31           in_specification = false;
    32         }
    33       }
    34     }
    35   }
    37   return true;
    38 }
    40 }  // namespace base

mercurial