Data size arithmetic was reviewed according to 64-bit MSVC complaints.
The warnings were addressed by migrating to size_t, rewriting the code,
or silencing the warnings by an explicit cast where appropriate.
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20171203203007.6628-1-simon@rozman.si>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16001.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -130,25 +130,20 @@ close_if_open(HANDLE h) |
| 130 | 130 |
static bool |
| 131 | 131 |
match(const WIN32_FIND_DATA *find, LPCTSTR ext) |
| 132 | 132 |
{
|
| 133 |
- int i; |
|
| 134 |
- |
|
| 135 | 133 |
if (find->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 136 | 134 |
{
|
| 137 | 135 |
return false; |
| 138 | 136 |
} |
| 139 | 137 |
|
| 140 |
- if (!_tcslen(ext)) |
|
| 138 |
+ if (*ext == TEXT('\0'))
|
|
| 141 | 139 |
{
|
| 142 | 140 |
return true; |
| 143 | 141 |
} |
| 144 | 142 |
|
| 145 |
- i = _tcslen(find->cFileName) - _tcslen(ext) - 1; |
|
| 146 |
- if (i < 1) |
|
| 147 |
- {
|
|
| 148 |
- return false; |
|
| 149 |
- } |
|
| 143 |
+ /* find the pointer to that last '.' in filename and match ext against the rest */ |
|
| 150 | 144 |
|
| 151 |
- return find->cFileName[i] == '.' && !_tcsicmp(find->cFileName + i + 1, ext); |
|
| 145 |
+ const TCHAR *p = _tcsrchr(find->cFileName, TEXT('.'));
|
|
| 146 |
+ return p && p != find->cFileName && _tcsicmp(p + 1, ext) == 0; |
|
| 152 | 147 |
} |
| 153 | 148 |
|
| 154 | 149 |
/* |
| ... | ... |
@@ -157,14 +152,14 @@ match(const WIN32_FIND_DATA *find, LPCTSTR ext) |
| 157 | 157 |
static bool |
| 158 | 158 |
modext(LPTSTR dest, int size, LPCTSTR src, LPCTSTR newext) |
| 159 | 159 |
{
|
| 160 |
- int i; |
|
| 160 |
+ size_t i; |
|
| 161 | 161 |
|
| 162 | 162 |
if (size > 0 && (_tcslen(src) + 1) <= size) |
| 163 | 163 |
{
|
| 164 | 164 |
_tcscpy(dest, src); |
| 165 | 165 |
dest [size - 1] = TEXT('\0');
|
| 166 | 166 |
i = _tcslen(dest); |
| 167 |
- while (--i >= 0) |
|
| 167 |
+ while (i-- > 0) |
|
| 168 | 168 |
{
|
| 169 | 169 |
if (dest[i] == TEXT('\\'))
|
| 170 | 170 |
{
|
| ... | ... |
@@ -280,7 +280,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) |
| 280 | 280 |
swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%s", 0, pid, msg); |
| 281 | 281 |
buf[_countof(buf) - 1] = '\0'; |
| 282 | 282 |
|
| 283 |
- WritePipeAsync(pipe, buf, wcslen(buf) * 2, count, events); |
|
| 283 |
+ WritePipeAsync(pipe, buf, (DWORD)(wcslen(buf) * 2), count, events); |
|
| 284 | 284 |
} |
| 285 | 285 |
|
| 286 | 286 |
static VOID |
| ... | ... |
@@ -308,7 +308,7 @@ ReturnError(HANDLE pipe, DWORD error, LPCWSTR func, DWORD count, LPHANDLE events |
| 308 | 308 |
L"0x%1!08x!\n%2!s!\n%3!s!", 0, 0, |
| 309 | 309 |
(LPWSTR) &result, 0, (va_list *) args); |
| 310 | 310 |
|
| 311 |
- WritePipeAsync(pipe, result, wcslen(result) * 2, count, events); |
|
| 311 |
+ WritePipeAsync(pipe, result, (DWORD)(wcslen(result) * 2), count, events); |
|
| 312 | 312 |
#ifdef UNICODE |
| 313 | 313 |
MsgToEventLog(MSG_FLAGS_ERROR, result); |
| 314 | 314 |
#else |
| ... | ... |
@@ -452,10 +452,10 @@ out: |
| 452 | 452 |
static BOOL |
| 453 | 453 |
GetStartupData(HANDLE pipe, STARTUP_DATA *sud) |
| 454 | 454 |
{
|
| 455 |
- size_t len; |
|
| 455 |
+ size_t size, len; |
|
| 456 | 456 |
BOOL ret = FALSE; |
| 457 | 457 |
WCHAR *data = NULL; |
| 458 |
- DWORD size, bytes, read; |
|
| 458 |
+ DWORD bytes, read; |
|
| 459 | 459 |
|
| 460 | 460 |
bytes = PeekNamedPipeAsync(pipe, 1, &exit_event); |
| 461 | 461 |
if (bytes == 0) |
| ... | ... |
@@ -1051,7 +1051,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam |
| 1051 | 1051 |
const wchar_t *fmt = L"netsh interface %s %s dns \"%s\" %s"; |
| 1052 | 1052 |
|
| 1053 | 1053 |
/* max cmdline length in wchars -- include room for worst case and some */ |
| 1054 |
- int ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1; |
|
| 1054 |
+ size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1; |
|
| 1055 | 1055 |
wchar_t *cmdline = malloc(ncmdline*sizeof(wchar_t)); |
| 1056 | 1056 |
if (!cmdline) |
| 1057 | 1057 |
{
|
| ... | ... |
@@ -1571,7 +1571,7 @@ RunOpenvpn(LPVOID p) |
| 1571 | 1571 |
{
|
| 1572 | 1572 |
DWORD written; |
| 1573 | 1573 |
WideCharToMultiByte(CP_UTF8, 0, sud.std_input, -1, input, input_size, NULL, NULL); |
| 1574 |
- WriteFile(stdin_write, input, strlen(input), &written, NULL); |
|
| 1574 |
+ WriteFile(stdin_write, input, (DWORD)strlen(input), &written, NULL); |
|
| 1575 | 1575 |
free(input); |
| 1576 | 1576 |
} |
| 1577 | 1577 |
|