mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Get rid of most _alloca use and remove ALLOCA().
This commit is contained in:
@ -355,7 +355,7 @@ unsigned NetAddressGetLocal (
|
||||
// Create a buffer to sort the addresses
|
||||
NetAddressNode * dst;
|
||||
if (found > count)
|
||||
dst = ALLOCA(NetAddressNode, found);
|
||||
dst = (NetAddressNode*)_alloca(found * sizeof(NetAddressNode));
|
||||
else
|
||||
dst = addresses;
|
||||
|
||||
|
@ -96,36 +96,38 @@ void MemoryGetStatus (MemoryStatus * status) {
|
||||
|
||||
//============================================================================
|
||||
void DiskGetStatus (ARRAY(DiskStatus) * disks) {
|
||||
for (;;) {
|
||||
DWORD length = GetLogicalDriveStrings(0, NULL);
|
||||
if (!length || length > 2048)
|
||||
break;
|
||||
DWORD length = GetLogicalDriveStrings(0, NULL);
|
||||
if (!length || length > 2048)
|
||||
return;
|
||||
|
||||
wchar_t * buffer = ALLOCA(wchar_t, length + 1);
|
||||
if (!GetLogicalDriveStringsW(length, buffer))
|
||||
break;
|
||||
|
||||
for (; *buffer; buffer += StrLen(buffer) + 1) {
|
||||
UINT driveType = GetDriveTypeW(buffer);
|
||||
if (driveType != DRIVE_FIXED)
|
||||
continue;
|
||||
|
||||
ULARGE_INTEGER freeBytes;
|
||||
ULARGE_INTEGER totalBytes;
|
||||
if (!GetDiskFreeSpaceExW(buffer, &freeBytes, &totalBytes, NULL))
|
||||
continue;
|
||||
|
||||
DiskStatus status;
|
||||
StrCopy(status.name, buffer, arrsize(status.name));
|
||||
|
||||
const uint64_t BYTES_PER_MB = 1024 * 1024;
|
||||
status.totalSpaceMB = unsigned(totalBytes.QuadPart / BYTES_PER_MB);
|
||||
status.freeSpaceMB = unsigned(freeBytes.QuadPart / BYTES_PER_MB);
|
||||
|
||||
disks->Add(status);
|
||||
}
|
||||
break;
|
||||
wchar_t* buffer = (wchar_t*)malloc((length + 1) * sizeof(wchar_t));
|
||||
wchar_t* origbuf = buffer;
|
||||
if (!GetLogicalDriveStringsW(length, buffer))
|
||||
{
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
for (; *buffer; buffer += StrLen(buffer) + 1) {
|
||||
UINT driveType = GetDriveTypeW(buffer);
|
||||
if (driveType != DRIVE_FIXED)
|
||||
continue;
|
||||
|
||||
ULARGE_INTEGER freeBytes;
|
||||
ULARGE_INTEGER totalBytes;
|
||||
if (!GetDiskFreeSpaceExW(buffer, &freeBytes, &totalBytes, NULL))
|
||||
continue;
|
||||
|
||||
DiskStatus status;
|
||||
StrCopy(status.name, buffer, arrsize(status.name));
|
||||
|
||||
const uint64_t BYTES_PER_MB = 1024 * 1024;
|
||||
status.totalSpaceMB = unsigned(totalBytes.QuadPart / BYTES_PER_MB);
|
||||
status.freeSpaceMB = unsigned(freeBytes.QuadPart / BYTES_PER_MB);
|
||||
|
||||
disks->Add(status);
|
||||
}
|
||||
free(origbuf);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -166,9 +166,11 @@ static void Rc4Codec (
|
||||
void * data
|
||||
) {
|
||||
// RC4 uses the same algorithm to both encrypt and decrypt
|
||||
uint8_t * temp = ALLOCA(uint8_t, bytes);
|
||||
uint8_t * temp = (uint8_t *)malloc(bytes);
|
||||
RC4((RC4_KEY *)key->handle, bytes, (const unsigned char *)data, temp);
|
||||
MemCopy(data, temp, bytes);
|
||||
|
||||
free(temp);
|
||||
}
|
||||
|
||||
} using namespace Crypt;
|
||||
@ -337,7 +339,7 @@ void CryptHashPassword (
|
||||
unsigned passlen = StrLen(password);
|
||||
unsigned userlen = StrLen(username);
|
||||
|
||||
wchar_t * buffer = ALLOCA(wchar_t, passlen + userlen);
|
||||
wchar_t * buffer = (wchar_t*)malloc(sizeof(wchar_t) * (passlen + userlen));
|
||||
StrCopy(buffer, password, passlen);
|
||||
StrCopy(buffer + passlen, username, userlen);
|
||||
StrLower(buffer + passlen); // lowercase the username
|
||||
@ -348,6 +350,8 @@ void CryptHashPassword (
|
||||
(userlen + passlen) * sizeof(buffer[0]),
|
||||
buffer
|
||||
);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -234,7 +234,7 @@ void PathSplitEmail (
|
||||
return;
|
||||
|
||||
// copy email address so we can tokenize it
|
||||
wchar_t * tmp = ALLOCA(wchar_t, len + 1);
|
||||
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1));
|
||||
StrCopy(tmp, emailAddr, len + 1);
|
||||
const wchar_t * work = tmp;
|
||||
|
||||
@ -255,9 +255,11 @@ void PathSplitEmail (
|
||||
ARRAY(wchar_t *) arr;
|
||||
while (StrTokenize(&work, token, arrsize(token), L".")) {
|
||||
unsigned toklen = StrLen(token);
|
||||
wchar_t * str = ALLOCA(wchar_t, toklen + 1);
|
||||
wchar_t * str = (wchar_t*)malloc(sizeof(wchar_t) * (toklen + 1));
|
||||
StrCopy(str, token, toklen + 1);
|
||||
arr.Add(str);
|
||||
|
||||
free(str);
|
||||
}
|
||||
|
||||
// copy domains to output parameters
|
||||
@ -285,6 +287,8 @@ void PathSplitEmail (
|
||||
if (subDomains)
|
||||
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
|
||||
#undef SUB_DOMAIN
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ unsigned GuidHash (const Uuid & uuid) {
|
||||
static const wchar_t s_hexChars[] = L"0123456789ABCDEF";
|
||||
const wchar_t * GuidToHex (const Uuid & uuid, wchar_t * dst, unsigned chars) {
|
||||
|
||||
wchar_t * str = ALLOCA(wchar_t, sizeof(uuid.data) * 2 + 1);
|
||||
wchar_t * str = (wchar_t*)malloc((sizeof(uuid.data) * 2 + 1) * sizeof(wchar_t));
|
||||
wchar_t * cur = str;
|
||||
|
||||
for (unsigned i = 0; i < sizeof(uuid.data); ++i) {
|
||||
@ -91,6 +91,8 @@ const wchar_t * GuidToHex (const Uuid & uuid, wchar_t * dst, unsigned chars) {
|
||||
*cur = 0;
|
||||
|
||||
StrCopy(dst, str, chars);
|
||||
|
||||
free(str);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@ -100,4 +102,4 @@ bool GuidFromHex (const uint8_t buf[], unsigned length, Uuid * uuid) {
|
||||
ASSERT(length == msizeof(Uuid, data));
|
||||
MemCopy(uuid->data, buf, msizeof(Uuid, data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user