summaryrefslogtreecommitdiffstats
path: root/base/stringprintf_unittest.cc
Commit message (Collapse)AuthorAgeFilesLines
* Remove wchar_t versions of StringPrintf from Androidhusky@chromium.org2012-08-011-0/+10
| | | | | | | | | | | BUG=137864 TEST=StringPrintfTest Review URL: https://chromiumcodereview.appspot.com/10800078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149397 0039d316-1c4b-4281-b951-d872f2087c98
* Enable positional parameters for base::vsnprintf and base::vswprintf on Windows.alexeypa@chromium.org2012-03-201-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to avoid bugs like http://code.google.com/p/chromium/issues/detail?id=118064 in the future. Positional parameters are supported by the VC++ runtime via the set of "_p" flavored printf-like routines. MSDN claims that "By default the positional functions behave identically to the non position ones, if no positional formatting is present." There is a little difference that require some attention though. Currently base::vsnprintf and base::vswprintf wrappers use "_s" functions (so called "security enhanced versions"). Judging by looking at the CRT code, _p functions implement the same checks as _s ones do. The base wrappers call the CRT routines so that count == (sizeOfBuffer - 1). This reduces most of the additional code in _vsnprintf_s (comparing to _vsprintf_p) to no-op. Namely: 1. When truncation happens the tail of the buffer is filled with a pattern: _SECURECRT__FILL_STRING(string, sizeInBytes, count + 1); This does not happen in our case because sizeInBytes == count + 1. 2. The special case check shown below was never true since sizeInBytes != count in our case: if (count == 0 && string == NULL && sizeInBytes == 0) 3. The following checks in _vsnprintf_s are also implemented in _vsnprintf_helper: _VALIDATE_RETURN(format != NULL, EINVAL, -1); _VALIDATE_RETURN(string != NULL && sizeInBytes > 0, EINVAL, -1); The only remaining difference between _vsnprintf_s and _vsprintf_p is that the former NULL-terminates the buffer and fills the rest a pattern if _vsnprintf_helper failed because of any reason other than truncation: string[0] = 0; _SECURECRT__FILL_STRING(string, sizeInBytes, 1); This CL write NULL to the end of the buffer in any error case (truncation or other reason). Review URL: http://codereview.chromium.org/9702002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127788 0039d316-1c4b-4281-b951-d872f2087c98
* Move StringPrintf into its own file and use the base namespace. Currently ↵brettw@chromium.org2010-08-171-0/+152
this has using directives for the functions so I don't have to change all files to use the namespace. No code changes to logic. TEST=it compiles + the included unit tests BUG=none Review URL: http://codereview.chromium.org/3181016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56299 0039d316-1c4b-4281-b951-d872f2087c98