Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/installer/mini_installer/mini_string.cc

Issue 1126163003: mini_installer: Change to use _countof rather than base's arraysize macro. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rm stdlib.h includes Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/mini_installer.cc ('k') | chrome/installer/mini_installer/mini_string_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698