| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/installer/mini_installer/mini_string.h" | 5 #include "chrome/installer/mini_installer/mini_string.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 // If we fail, we do not want to leave the string with partially copied | 62 // If we fail, we do not want to leave the string with partially copied |
| 63 // contents. The reason for this is that we use these strings mostly for | 63 // contents. The reason for this is that we use these strings mostly for |
| 64 // named objects such as files. If we copy a partial name, then that could | 64 // named objects such as files. If we copy a partial name, then that could |
| 65 // match with something we do not want it to match with. | 65 // match with something we do not want it to match with. |
| 66 // Furthermore, since SafeStrCopy is called from SafeStrCat, we do not | 66 // Furthermore, since SafeStrCopy is called from SafeStrCat, we do not |
| 67 // want to mutate the string in case the caller handles the error of a | 67 // want to mutate the string in case the caller handles the error of a |
| 68 // failed concatenation. For example: | 68 // failed concatenation. For example: |
| 69 // | 69 // |
| 70 // wchar_t buf[5] = {0}; | 70 // wchar_t buf[5] = {0}; |
| 71 // if (!SafeStrCat(buf, arraysize(buf), kLongName)) | 71 // if (!SafeStrCat(buf, _countof(buf), kLongName)) |
| 72 // SafeStrCat(buf, arraysize(buf), kShortName); | 72 // SafeStrCat(buf, _countof(buf), kShortName); |
| 73 // | 73 // |
| 74 // If we were to return false in the first call to SafeStrCat but still | 74 // If we were to return false in the first call to SafeStrCat but still |
| 75 // mutate the buffer, the buffer will be in an unexpected state. | 75 // mutate the buffer, the buffer will be in an unexpected state. |
| 76 *dest = L'\0'; | 76 *dest = L'\0'; |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Safer replacement for lstrcat function. | 80 // Safer replacement for lstrcat function. |
| 81 bool SafeStrCat(wchar_t* dest, size_t dest_size, const wchar_t* src) { | 81 bool SafeStrCat(wchar_t* dest, size_t dest_size, const wchar_t* src) { |
| 82 // Use SafeStrLen instead of lstrlen just in case the |dest| buffer isn't | 82 // Use SafeStrLen instead of lstrlen just in case the |dest| buffer isn't |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return NULL; | 153 return NULL; |
| 154 | 154 |
| 155 wchar_t* current = &path[size - 1]; | 155 wchar_t* current = &path[size - 1]; |
| 156 while (current != path && L'\\' != *current) | 156 while (current != path && L'\\' != *current) |
| 157 --current; | 157 --current; |
| 158 | 158 |
| 159 return (current == path) ? NULL : (current + 1); | 159 return (current == path) ? NULL : (current + 1); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace mini_installer | 162 } // namespace mini_installer |
| OLD | NEW |