Compare commits
35 Commits
cleanup/er
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edbc2b6766 | ||
|
|
230401c1d0 | ||
|
|
c99cc7922d | ||
|
|
048f578ed5 | ||
|
|
633193d5b3 | ||
|
|
ac8ff7f6e9 | ||
|
|
0a801b7420 | ||
|
|
a15dd68674 | ||
|
|
861ed1c446 | ||
|
|
61ce21d35f | ||
|
|
2cf9bb4f88 | ||
|
|
98205461d6 | ||
|
|
681deff3d7 | ||
|
|
34537f9931 | ||
|
|
60b8903833 | ||
|
|
5cf3207119 | ||
|
|
4afe002d09 | ||
|
|
b81e66b57f | ||
|
|
f42599fb46 | ||
|
|
0630899b66 | ||
|
|
cb18542e6f | ||
|
|
7f51543e7f | ||
|
|
5463295790 | ||
|
|
1e3e622fe3 | ||
|
|
2555f31a8b | ||
|
|
59a2a0af19 | ||
|
|
36ecc0c3c2 | ||
|
|
61eb7d8953 | ||
|
|
319b2f0d29 | ||
|
|
7c3f3b2f0a | ||
|
|
273365f68e | ||
|
|
a56e34f215 | ||
|
|
921c4ccd8b | ||
|
|
ad5317d876 | ||
|
|
89239f3668 |
@@ -176,7 +176,8 @@ s32 ConvertDateToDays(u16 year, u8 month, u8 day) {
|
||||
}
|
||||
|
||||
validDate:
|
||||
daysOfYear = day - 1 + DAYS_OF_YEAR[month - 1];
|
||||
daysOfYear = day - 1;
|
||||
daysOfYear += DAYS_OF_YEAR[month - 1];
|
||||
if (month >= 3) {
|
||||
isLeapYear = 0;
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
|
||||
@@ -204,9 +205,8 @@ void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days) {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
u16 currentYear = *year;
|
||||
s32 previousDays = days;
|
||||
BOOL leapYear = (currentYear % 4 == 0 && currentYear % 100 != 0) || currentYear % 400 == 0;
|
||||
BOOL leapYear = (*year % 4 == 0 && *year % 100 != 0) || *year % 400 == 0;
|
||||
days -= 365 + (leapYear != FALSE);
|
||||
if (days < 0) {
|
||||
days = previousDays;
|
||||
@@ -217,20 +217,15 @@ void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days) {
|
||||
|
||||
for (;;) {
|
||||
s32 previousDays = days;
|
||||
if (*month == 2) {
|
||||
BOOL leapYear = IsLeapYear(*year);
|
||||
if (leapYear) {
|
||||
days -= 29;
|
||||
} else {
|
||||
days -= DAYS_OF_MONTH[*month - 1];
|
||||
}
|
||||
if (*month == 2 && IsLeapYear(*year)) {
|
||||
days -= 29;
|
||||
} else {
|
||||
days -= DAYS_OF_MONTH[*month - 1];
|
||||
}
|
||||
if (days < 0) {
|
||||
*day += previousDays;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
*month = *month + 1;
|
||||
*month += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1043,6 +1043,7 @@ closeList:
|
||||
|
||||
NWC24Err NWC24iCheckDlHeaderConsistency(DlTaskListHeader* header, BOOL repair) {
|
||||
NWC24DlTask task;
|
||||
DlTaskData* taskData = (DlTaskData*)&task;
|
||||
NWC24DlTask* taskPointer = &task;
|
||||
NWC24DlId taskId;
|
||||
NWC24Err result;
|
||||
@@ -1064,14 +1065,14 @@ NWC24Err NWC24iCheckDlHeaderConsistency(DlTaskListHeader* header, BOOL repair) {
|
||||
if (result < NWC24_OK) {
|
||||
if (ValidateDlTask(taskPointer, FALSE) == NWC24_OK) {
|
||||
result = DeleteDlTask(taskPointer);
|
||||
if (result >= NWC24_OK) { ((DlTaskData*)taskPointer)->id = 0xffff; }
|
||||
if (result >= NWC24_OK) { taskData->id = 0xffff; }
|
||||
}
|
||||
} else {
|
||||
currentHeader = GetCachedDlHeader();
|
||||
if (taskId >= currentHeader->taskCount && (s16)((DlTaskData*)taskPointer)->subTaskCount == 0) {
|
||||
if (taskId >= currentHeader->taskCount && (s16)taskData->subTaskCount == 0) {
|
||||
if (ValidateDlTask(taskPointer, FALSE) == NWC24_OK) {
|
||||
result = DeleteDlTask(taskPointer);
|
||||
if (result >= NWC24_OK) { ((DlTaskData*)taskPointer)->id = 0xffff; }
|
||||
if (result >= NWC24_OK) { taskData->id = 0xffff; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,8 +555,8 @@ NWC24Err NWC24iMBoxFlushHeader(NWC24MBoxType type) {
|
||||
return result != NWC24_OK ? result : closeResult;
|
||||
}
|
||||
|
||||
static inline void GetOldestMsgId(const MBCHeader* header, u32* id) {
|
||||
*id = header->oldestId;
|
||||
static inline void GetOldestMsgId(const MBCHeader* header, u32* msgId) {
|
||||
*msgId = header->oldestId;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iMBoxCheck(NWC24MBoxType type, u32 size) {
|
||||
|
||||
@@ -231,12 +231,17 @@ static NWC24Err QEncode(char* encoded, u32 encodedCapacity, u32* encodedSize, u8
|
||||
}
|
||||
|
||||
static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded, u32 encodedSize, u32* encodedSizeOut, int flags) {
|
||||
u32 decodedOffset = 0;
|
||||
u32 encodedOffset;
|
||||
u32 decodedOffset;
|
||||
u8 value;
|
||||
char* input;
|
||||
char* output;
|
||||
u8 value = 0;
|
||||
NWC24Err result = NWC24_OK;
|
||||
NWC24Err result;
|
||||
int valid;
|
||||
|
||||
decodedOffset = 0;
|
||||
value = 0;
|
||||
result = NWC24_OK;
|
||||
|
||||
if (decoded == NULL)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
@@ -255,7 +260,7 @@ static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, ch
|
||||
input = encoded;
|
||||
output = decoded;
|
||||
for (encodedOffset = 0; encodedOffset < encodedSize; encodedOffset++) {
|
||||
if (decodedCapacity <= decodedOffset) {
|
||||
if (decodedOffset >= decodedCapacity) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
break;
|
||||
}
|
||||
@@ -264,48 +269,48 @@ static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, ch
|
||||
input++;
|
||||
decodedOffset++;
|
||||
} else if (*input == '=' && encodedOffset + 2 < encodedSize) {
|
||||
BOOL validHex = TRUE;
|
||||
u32 inputAfterEqual = encodedOffset + 1;
|
||||
char* current = ++input;
|
||||
if (*current == ' ' || *current == '\t') {
|
||||
char* next = current + 1;
|
||||
u32 scan = 1;
|
||||
while (inputAfterEqual + scan + 1 < encodedSize) {
|
||||
if (*next == '\r' && next[1] == '\n') {
|
||||
inputAfterEqual += scan;
|
||||
current = next;
|
||||
input++;
|
||||
encodedOffset++;
|
||||
valid = 1;
|
||||
if (*input == ' ' || *input == '\t') {
|
||||
char* scan = input + 1;
|
||||
u32 scanLen = 1;
|
||||
while (encodedOffset + scanLen + 1 < encodedSize) {
|
||||
if (*scan == '\r' && scan[1] == '\n') {
|
||||
input = scan;
|
||||
encodedOffset += scanLen;
|
||||
break;
|
||||
}
|
||||
if (*next != ' ' && *next != '\t') {
|
||||
if (*scan != ' ' && *scan != '\t') {
|
||||
break;
|
||||
}
|
||||
next++;
|
||||
scan++;
|
||||
scanLen++;
|
||||
}
|
||||
}
|
||||
if (*current == '\r' && current[1] == '\n') {
|
||||
current += 2;
|
||||
encodedOffset = inputAfterEqual + 1;
|
||||
input = current;
|
||||
if (*input == '\r' && input[1] == '\n') {
|
||||
input += 2;
|
||||
encodedOffset++;
|
||||
} else {
|
||||
int high = Util_xtoi(*current);
|
||||
int high = Util_xtoi(*input);
|
||||
int low;
|
||||
if (high >= 0) {
|
||||
value = (high & 0x0F) << 4;
|
||||
} else {
|
||||
valid = 0;
|
||||
}
|
||||
if (high < 0) { validHex = FALSE; }
|
||||
low = Util_xtoi(current[1]);
|
||||
low = Util_xtoi(input[1]);
|
||||
if (low >= 0) {
|
||||
value |= low & 0x0F;
|
||||
value = (value | (low & 0x0F)) & 0xFF;
|
||||
} else {
|
||||
valid = 0;
|
||||
}
|
||||
if (low < 0) { validHex = FALSE; }
|
||||
current += 2;
|
||||
if (validHex) {
|
||||
input += 2;
|
||||
if (valid) {
|
||||
*output++ = (char)value;
|
||||
decodedOffset++;
|
||||
}
|
||||
encodedOffset = inputAfterEqual + 1;
|
||||
input = current;
|
||||
encodedOffset++;
|
||||
}
|
||||
} else {
|
||||
*output++ = *input++;
|
||||
@@ -331,90 +336,96 @@ NWC24Err NWC24DecodeQuotedPrintable(char* decoded, u32 decodedCapacity, u32* dec
|
||||
|
||||
static NWC24Err ConcatEncodedText(char* encoded, u32 encodedCapacity, u32* encodedSize, char encoding, u8* decoded, u32 decodedSize,
|
||||
u32* decodedSizeOut);
|
||||
static inline NWC24Err AppendWordPrefix(char* encoded, u32 capacity) {
|
||||
if (Mail_strlen(encoded) + 2 < capacity) {
|
||||
Mail_strncat(encoded, "=?", 2);
|
||||
} else { return NWC24_ERR_OVERFLOW; }
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static inline NWC24Err AppendWordSeparator(char* encoded, u32 capacity) {
|
||||
if (Mail_strlen(encoded) + 2 < capacity) {
|
||||
Mail_strncat(encoded, "?", 1);
|
||||
} else { return NWC24_ERR_OVERFLOW; }
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static inline NWC24Err AppendWordSuffix(char* encoded, u32 capacity) {
|
||||
if (Mail_strlen(encoded) + 2 < capacity) {
|
||||
Mail_strncat(encoded, "?=", 2);
|
||||
} else { return NWC24_ERR_OVERFLOW; }
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static inline NWC24Err AppendWordCharset(char* encoded, u32 capacity, char* charset, u32 charsetSize) {
|
||||
if (charset == NULL) { return NWC24_ERR_INVALID_VALUE; }
|
||||
if (charsetSize + Mail_strlen(encoded) < capacity) {
|
||||
u32 length = Mail_strlen(charset);
|
||||
Mail_strncat(encoded, charset, length);
|
||||
} else { return NWC24_ERR_OVERFLOW; }
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static inline NWC24Err AppendWordEncoding(char* encoded, u32 capacity, char encoding) {
|
||||
char encodingText[1];
|
||||
encodingText[0] = encoding;
|
||||
if (encoding != 'B' && encoding != 'b' && encoding != 'Q' && encoding != 'q') {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
static inline NWC24Err AppendBounded(char* encoded, u32 encodedCapacity, u32 needed, const char* str, u32 strLen) {
|
||||
NWC24Err result;
|
||||
if (Mail_strlen(encoded) + needed < encodedCapacity) {
|
||||
Mail_strncat(encoded, str, strLen);
|
||||
result = NWC24_OK;
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
if (Mail_strlen(encoded) + 1 < capacity) {
|
||||
Mail_strncat(encoded, encodingText, 1);
|
||||
} else { return NWC24_ERR_OVERFLOW; }
|
||||
return NWC24_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err EncodeWord(char* encoded, u32 encodedCapacity, u32* encodedSize, char* charset, u32 charsetSize, char encoding, u8* decoded,
|
||||
u32 decodedSize, u32* decodedSizeOut) {
|
||||
NWC24Err result;
|
||||
BOOL encodeOverflow = FALSE;
|
||||
|
||||
if (decodedSizeOut != NULL) { *decodedSizeOut = 0; }
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 0;
|
||||
}
|
||||
if (encodedCapacity == 0) {
|
||||
if (decodedSizeOut != NULL) { *decodedSizeOut = 0; }
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 0;
|
||||
}
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
*encoded = '\0';
|
||||
if (encodedSize != NULL) { *encodedSize = 1; }
|
||||
|
||||
result = AppendWordPrefix(encoded, encodedCapacity);
|
||||
if (result != NWC24_OK) { *encoded = '\0'; return result; }
|
||||
|
||||
result = AppendWordCharset(encoded, encodedCapacity, charset, charsetSize);
|
||||
if (result != NWC24_OK) { *encoded = '\0'; return result; }
|
||||
|
||||
result = AppendWordSeparator(encoded, encodedCapacity);
|
||||
if (result != NWC24_OK) { *encoded = '\0'; return result; }
|
||||
|
||||
result = AppendWordEncoding(encoded, encodedCapacity, encoding);
|
||||
if (result != NWC24_OK) { *encoded = '\0'; return result; }
|
||||
|
||||
result = AppendWordSeparator(encoded, encodedCapacity);
|
||||
if (result != NWC24_OK) { *encoded = '\0'; return result; }
|
||||
|
||||
if (encodedSize != NULL) {
|
||||
*encodedSize = 1;
|
||||
}
|
||||
result = AppendBounded(encoded, encodedCapacity, 2, "=?", 2);
|
||||
if (result != NWC24_OK) {
|
||||
*encoded = '\0';
|
||||
goto done;
|
||||
}
|
||||
if (charset != NULL) {
|
||||
result = AppendBounded(encoded, encodedCapacity, charsetSize, charset, Mail_strlen(charset));
|
||||
} else {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (result != NWC24_OK) {
|
||||
*encoded = '\0';
|
||||
goto done;
|
||||
}
|
||||
result = AppendBounded(encoded, encodedCapacity, 2, "?", 1);
|
||||
if (result != NWC24_OK) {
|
||||
*encoded = '\0';
|
||||
goto done;
|
||||
}
|
||||
{
|
||||
char value[1];
|
||||
value[0] = encoding;
|
||||
if (encoding == 'B' || encoding == 'b' || encoding == 'Q' || encoding == 'q') {
|
||||
result = AppendBounded(encoded, encodedCapacity, 1, value, 1);
|
||||
} else {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (result != NWC24_OK) {
|
||||
*encoded = '\0';
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
result = AppendBounded(encoded, encodedCapacity, 2, "?", 1);
|
||||
if (result != NWC24_OK) {
|
||||
*encoded = '\0';
|
||||
goto done;
|
||||
}
|
||||
result = ConcatEncodedText(encoded, encodedCapacity, encodedSize, encoding, decoded, decodedSize, decodedSizeOut);
|
||||
if (result != NWC24_OK && result != NWC24_ERR_OVERFLOW) {
|
||||
*encoded = '\0';
|
||||
*decodedSizeOut = 1;
|
||||
return result;
|
||||
goto done;
|
||||
}
|
||||
if (result == NWC24_ERR_OVERFLOW) { encodeOverflow = TRUE; }
|
||||
result = AppendWordSuffix(encoded, encodedCapacity);
|
||||
if (result == NWC24_ERR_OVERFLOW) {
|
||||
encodeOverflow = TRUE;
|
||||
}
|
||||
result = AppendBounded(encoded, encodedCapacity, 2, "?=", 2);
|
||||
if (result != NWC24_OK) {
|
||||
*encoded = '\0';
|
||||
*decodedSizeOut = 1;
|
||||
return result;
|
||||
goto done;
|
||||
}
|
||||
*encodedSize = Mail_strlen(encoded) + 1;
|
||||
if (result == NWC24_OK && encodeOverflow) { result = NWC24_ERR_OVERFLOW; }
|
||||
if (result == NWC24_OK) {
|
||||
if (encodeOverflow) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -447,15 +458,14 @@ NWC24Err NWC24EncodeWord(u8* encoded, u32 encodedCapacity, u32* encodedSize, cha
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetSize, char* encoded, u32 encodedSize);
|
||||
static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetSize, char* encoded, u32 encodedSize) NO_INLINE;
|
||||
static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* decodedSize, char encoding, char* encoded, u32 encodedSize,
|
||||
u32* encodedSizeOut);
|
||||
|
||||
static BOOL CopyWithoutLinearWhiteSpaces(char* output, int* outputSize, char* input, int inputSize) {
|
||||
BOOL afterNewline = FALSE;
|
||||
u32 outputOffset = 0;
|
||||
BOOL afterNewline = FALSE;
|
||||
s32 capacity;
|
||||
u32 limit;
|
||||
|
||||
if (output == NULL || outputSize == NULL || *outputSize == 0) {
|
||||
return FALSE;
|
||||
@@ -466,8 +476,7 @@ static BOOL CopyWithoutLinearWhiteSpaces(char* output, int* outputSize, char* in
|
||||
*outputSize = 1;
|
||||
return TRUE;
|
||||
}
|
||||
limit = capacity - 1U;
|
||||
while (outputOffset < limit && inputSize != 0 && *input != '\0') {
|
||||
while (outputOffset < capacity - 1U && inputSize != 0 && *input != '\0') {
|
||||
char value = *input;
|
||||
switch (value) {
|
||||
case '\r':
|
||||
@@ -501,79 +510,90 @@ static BOOL CopyWithoutLinearWhiteSpaces(char* output, int* outputSize, char* in
|
||||
}
|
||||
|
||||
static inline char* FindMarker(char* input, u32 size, const char* marker) {
|
||||
s32 offset;
|
||||
u32 markerLength = Mail_strlen(marker);
|
||||
u32 offset;
|
||||
for (offset = 0; offset <= size; offset++) {
|
||||
char* current = input + offset;
|
||||
if (Mail_strncmp(current, marker, markerLength) == 0)
|
||||
return current;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static inline char* FindMarkerAfterPrefix(char* input, u32 size, u32 prefix, const char* marker) {
|
||||
u32 markerLength = Mail_strlen(marker);
|
||||
char* current = input + prefix;
|
||||
u32 offset;
|
||||
for (offset = 0; offset <= size; offset++) {
|
||||
if (Mail_strncmp(current, marker, markerLength) == 0) {
|
||||
return input + offset + prefix;
|
||||
}
|
||||
current++;
|
||||
char* pos = input + offset;
|
||||
if (Mail_strncmp(pos, marker, markerLength) == 0)
|
||||
return input + offset;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline NWC24Err ExtractWordEncoding(char* encoding, u32* encodingSize, char* encoded, u32 encodedSize) {
|
||||
char* delimiter = FindMarkerAfterPrefix(encoded, encodedSize, 0, "?");
|
||||
if (delimiter == NULL) { return NWC24_ERR_INVALID_VALUE; }
|
||||
*encoding = delimiter[1];
|
||||
*encodingSize = 2;
|
||||
return NWC24_OK;
|
||||
}
|
||||
static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded,
|
||||
u32 encodedSize, u32* encodedSizeOut) {
|
||||
char* encodedWord;
|
||||
char* encodedWordPosition;
|
||||
u32 encodedLength;
|
||||
u32 consumedSize;
|
||||
u32 decodedLength;
|
||||
int encodedLength;
|
||||
NWC24Err result;
|
||||
|
||||
if (encodedSizeOut != NULL) { *encodedSizeOut = 0; }
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = 0;
|
||||
}
|
||||
if (decodedCapacity == 0) {
|
||||
if (encodedSizeOut != NULL) { *encodedSizeOut = 0; }
|
||||
if (encodedSizeOut != NULL)
|
||||
*encodedSizeOut = 0;
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
*decoded = '\0';
|
||||
if (decodedSize != NULL) { *decodedSize = 1; }
|
||||
if (encodedSizeOut != NULL) { *encodedSizeOut = 0; }
|
||||
encodedWord = FindMarker(encoded, encodedSize, "=?");
|
||||
if (encodedWord == encoded) {
|
||||
char encoding;
|
||||
result = ExtractCharset(charsetData, charsetCapacity, &consumedSize, encodedWord, encodedSize);
|
||||
if (result != NWC24_OK) { return result; }
|
||||
encodedLength = consumedSize;
|
||||
result = ExtractWordEncoding(&encoding, &consumedSize, encodedWord + encodedLength, encodedSize - encodedLength);
|
||||
if (result != NWC24_OK) { return result; }
|
||||
encodedLength += consumedSize;
|
||||
result = ExtractEncodedText(decoded, decodedCapacity, &decodedLength, encoding, encodedWord + encodedLength,
|
||||
encodedSize - encodedLength, &consumedSize);
|
||||
if (result != NWC24_OK) { return result; }
|
||||
encodedLength += consumedSize;
|
||||
} else {
|
||||
u32 localSize;
|
||||
if (encodedWord != NULL) {
|
||||
encodedLength = encodedWord - encoded;
|
||||
} else {
|
||||
encodedLength = STD_strnlen(encoded, encodedSize);
|
||||
if (decodedSize != NULL) {
|
||||
*decodedSize = 1;
|
||||
}
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = 0;
|
||||
}
|
||||
encodedWordPosition = FindMarker((char*)encoded, encodedSize, "=?");
|
||||
if (encodedWordPosition == (char*)encoded) {
|
||||
result = ExtractCharset(charsetData, charsetCapacity, &consumedSize, (char*)encoded, encodedSize);
|
||||
if (result != NWC24_OK) {
|
||||
return result;
|
||||
}
|
||||
encodedLength = consumedSize;
|
||||
{
|
||||
const char* marker = "?";
|
||||
u32 markerLength = Mail_strlen(marker);
|
||||
u32 offset;
|
||||
char* delimiter = NULL;
|
||||
char* current;
|
||||
for (offset = 0; offset <= encodedSize - consumedSize; offset++) {
|
||||
current = (char*)encodedWordPosition + consumedSize + offset;
|
||||
if (Mail_strncmp((char*)current, marker, markerLength) == 0) {
|
||||
delimiter = current;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (delimiter == 0) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
{
|
||||
char encoding = delimiter[1];
|
||||
consumedSize = 2;
|
||||
encodedLength += consumedSize;
|
||||
result = ExtractEncodedText(decoded, decodedCapacity, &decodedLength, encoding, encoded + encodedLength, encodedSize - encodedLength,
|
||||
&consumedSize);
|
||||
if (result != NWC24_OK) {
|
||||
return result;
|
||||
}
|
||||
encodedLength += consumedSize;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
u32 localSize = decodedCapacity;
|
||||
if (encodedWordPosition == NULL) {
|
||||
encodedLength = STD_strnlen(encoded, encodedSize);
|
||||
} else {
|
||||
encodedLength = encodedWordPosition - (char*)encoded;
|
||||
}
|
||||
localSize = decodedCapacity;
|
||||
if (!CopyWithoutLinearWhiteSpaces(decoded, (int*)&localSize, encoded, encodedLength)) {
|
||||
*decodedSize = localSize;
|
||||
if (encodedSizeOut != NULL) { *encodedSizeOut = encodedLength; }
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = encodedLength;
|
||||
}
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
decodedLength = localSize;
|
||||
if (encodedWord != NULL) {
|
||||
if (encodedWordPosition != NULL) {
|
||||
BOOL whitespaceOnly = TRUE;
|
||||
u32 offset;
|
||||
for (offset = 0; offset < localSize && decoded[offset] != '\0'; offset++) {
|
||||
@@ -588,18 +608,22 @@ static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded
|
||||
}
|
||||
}
|
||||
}
|
||||
*decodedSize = decodedLength;
|
||||
if (encodedSizeOut != NULL) { *encodedSizeOut = encodedLength; }
|
||||
return NWC24_OK;
|
||||
if (decodedSize != NULL) {
|
||||
*decodedSize = decodedLength;
|
||||
}
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = encodedLength;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24DecodeMIMEHeaderFieldBody(u8* charsetData, u32 charsetDataSize, u8* decoded, u32 decodedCapacity, u32* decodedSize, u8* encoded,
|
||||
u32 encodedSize) {
|
||||
int result = 0;
|
||||
char* input;
|
||||
s32 inputSize;
|
||||
u8* output;
|
||||
s32 remainingCapacity;
|
||||
u32 inputSize;
|
||||
u32 capacity;
|
||||
u8* input;
|
||||
|
||||
if (decodedSize == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
@@ -615,21 +639,21 @@ NWC24Err NWC24DecodeMIMEHeaderFieldBody(u8* charsetData, u32 charsetDataSize, u8
|
||||
*decoded = 0;
|
||||
*charsetData = 0;
|
||||
*decodedSize = 1;
|
||||
input = (char*)encoded;
|
||||
inputSize = encodedSize;
|
||||
capacity = decodedCapacity;
|
||||
output = decoded;
|
||||
remainingCapacity = decodedCapacity;
|
||||
while ((s32)inputSize > 0 && remainingCapacity > 0 && *input != '\0') {
|
||||
input = encoded;
|
||||
while ((s32)inputSize > 0 && (s32)capacity > 0 && *input != '\0') {
|
||||
u32 copiedSize = 0;
|
||||
u32 consumedSize;
|
||||
result =
|
||||
DecodeWord((char*)charsetData, charsetDataSize, (char*)output, remainingCapacity, &copiedSize, (char*)input, inputSize, &consumedSize);
|
||||
DecodeWord((char*)charsetData, charsetDataSize, (char*)output, capacity, &copiedSize, (char*)input, inputSize, &consumedSize);
|
||||
if (copiedSize == 0) {
|
||||
break;
|
||||
}
|
||||
copiedSize--;
|
||||
output += copiedSize;
|
||||
remainingCapacity -= copiedSize;
|
||||
capacity -= copiedSize;
|
||||
*decodedSize += copiedSize;
|
||||
input += consumedSize;
|
||||
inputSize -= consumedSize;
|
||||
@@ -668,8 +692,6 @@ static NWC24Err ConcatEncodedText(char* encoded, u32 encodedCapacity, u32* encod
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetSize, char* encoded, u32 encodedSize) {
|
||||
char* start;
|
||||
char* end;
|
||||
@@ -682,7 +704,7 @@ static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetS
|
||||
if (start == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
end = FindMarkerAfterPrefix(start, encodedSize - (u32)(start + 2 - encoded), 2, "?");
|
||||
end = FindMarker(start + 2, encodedSize - (u32)(start + 2 - encoded), "?");
|
||||
if (end == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
@@ -690,21 +712,12 @@ static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetS
|
||||
if (charsetLength < charsetCapacity) {
|
||||
Mail_strncpy(charset, start + 2, charsetLength);
|
||||
charset[charsetLength] = '\0';
|
||||
} else { return NWC24_ERR_OVERFLOW; }
|
||||
} else {
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
*charsetSize = charsetLength + 2;
|
||||
return NWC24_OK;
|
||||
}
|
||||
static inline char* FindMarkerOffsetPrefix(char* input, u32 size, u32 prefix, const char* marker) {
|
||||
u32 markerLength = Mail_strlen(marker);
|
||||
u32 offset;
|
||||
for (offset = 0; offset <= size; offset++) {
|
||||
if (Mail_strncmp(input + offset + prefix, marker, markerLength) == 0) {
|
||||
return input + prefix + offset;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* decodedSize, char encoding, char* encoded, u32 encodedSize,
|
||||
u32* encodedSizeOut) {
|
||||
@@ -713,7 +726,9 @@ static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* deco
|
||||
int length;
|
||||
NWC24Err result;
|
||||
|
||||
if (encoded == NULL) { return NWC24_ERR_INVALID_VALUE; }
|
||||
if (encoded == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (decodedSize == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
@@ -726,11 +741,11 @@ static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* deco
|
||||
if (start == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
end = FindMarkerOffsetPrefix(start, encodedSize - (u32)(start + 1 - encoded), 1, "?=");
|
||||
end = FindMarker(start + 1, encodedSize - (u32)(start + 1 - encoded), "?=");
|
||||
if (end == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
length = end - (start + 1);
|
||||
length = (u32)(end - (start + 1));
|
||||
if (encoding == 'B' || encoding == 'b') {
|
||||
result = NWC24Base64Decode((u8*)(start + 1), length, (u8*)decoded, decodedCapacity - 1, decodedSize);
|
||||
if (result == NWC24_OK || result == NWC24_ERR_OVERFLOW) {
|
||||
@@ -746,6 +761,8 @@ static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* deco
|
||||
} else {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
if (end != NULL) { *encodedSizeOut = (u32)(end - encoded) + 2; }
|
||||
if (end != NULL) {
|
||||
*encodedSizeOut = (u32)(end - encoded) + 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,25 @@ static NWC24File* m_pFile;
|
||||
|
||||
static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType type);
|
||||
static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteSubjectField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type);
|
||||
static inline NWC24Err WriteSubjectField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->subject.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "Subject: ");
|
||||
Mail_strncat(buffer, msg->subject.ptr, 1021);
|
||||
Mail_strncat(buffer, "\r\n", 1024);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err SynthesizeAddrStr(const NWC24Data* address, u32 type, char* dest, s32 capacity, u32* length);
|
||||
static NWC24Err WriteSMTP_MAILFROM(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteSMTP_RCPTTO(NWC24MsgObjPrivate* msg);
|
||||
@@ -53,22 +71,6 @@ static inline NWC24Err WriteString(NWC24MsgObjPrivate* msg, char* buffer) {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline NWC24Err WriteSubjectField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->subject.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "Subject: ");
|
||||
Mail_strncat(buffer, msg->subject.ptr, 1021);
|
||||
Mail_strncat(buffer, "\r\n", 1024);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteSMTPData(NWC24MsgObjPrivate* msg, const char* text) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
@@ -306,7 +308,7 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
|
||||
CHECK_WRITE(WriteIconNewField(msg));
|
||||
if (msg->msgBoardFlags.raw != 0) {
|
||||
CHECK_WRITE(WriteMBNoReplyField(msg));
|
||||
{ u16 dateFlags = msg->msgBoardFlags.raw; CHECK_WRITE(WriteMBRegDateField(msg, dateFlags)); }
|
||||
CHECK_WRITE(WriteMBRegDateField(msg, msg->msgBoardFlags.raw & 0xFFFF));
|
||||
CHECK_WRITE(WriteMBDelayField(msg, msg->msgBoardFlags.raw & 0xFF0000));
|
||||
}
|
||||
}
|
||||
@@ -334,8 +336,9 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
|
||||
if (!(msg->type & 0x10000))
|
||||
msg->unk_0x10 = msg->length;
|
||||
text.ptr = (const void*)msg->length;
|
||||
{ NWC24Err textResult = WritePlainText(msg);
|
||||
err = textResult == NWC24_ERR_NULL ? NWC24_OK : textResult; }
|
||||
err = WritePlainText(msg);
|
||||
if (err == NWC24_ERR_NULL)
|
||||
err = NWC24_OK;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
@@ -423,6 +426,10 @@ static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg) {
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static inline u32 EstimateBase64Size(u32 size) {
|
||||
return (size * 4 + 2) / 3 + size / 57 * 2 + 4;
|
||||
}
|
||||
|
||||
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type) {
|
||||
u32 total = 0;
|
||||
u32 textSize = 0;
|
||||
@@ -430,7 +437,7 @@ static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType ty
|
||||
NWC24Err err;
|
||||
for (index = 0; index < msg->numAttached; ++index) {
|
||||
u32 size = msg->attachedSize[index];
|
||||
total += (size * 4 + 2) / 3 + size / 57 * 2 + 4;
|
||||
total += EstimateBase64Size(size);
|
||||
}
|
||||
switch (msg->encoding) {
|
||||
case NWC24_ENC_7BIT:
|
||||
@@ -438,7 +445,7 @@ static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType ty
|
||||
textSize = msg->text.size;
|
||||
break;
|
||||
case NWC24_ENC_BASE64:
|
||||
textSize = (msg->text.size * 4 + 2) / 3 + msg->text.size / 57 * 2 + 4;
|
||||
textSize = EstimateBase64Size(msg->text.size);
|
||||
break;
|
||||
case NWC24_ENC_QUOTED_PRINTABLE:
|
||||
textSize = msg->text.size * 4 / 3;
|
||||
@@ -456,6 +463,7 @@ static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType ty
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
|
||||
static NWC24Err SynthesizeAddrStr(const NWC24Data* address, u32 type, char* dest, s32 capacity, u32* length) {
|
||||
char id[32];
|
||||
NWC24Err err = NWC24_OK;
|
||||
|
||||
@@ -8,10 +8,11 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
|
||||
NWC24Err ReadBase64Data(NWC24File* file, const NWC24Data* data, u8* output, u32 capacity, u32* outputSize);
|
||||
NWC24Err ReadQPText(const NWC24MsgObjPrivate* msg, NWC24File* file, char* output, u32 capacity);
|
||||
|
||||
static inline NWC24Err SelectMBox(const NWC24MsgObjPrivate* msg, NWC24MBoxType* type) {
|
||||
if (msg->type & 0x10)
|
||||
static inline NWC24Err SelectMBox(const NWC24MsgObj* msg, NWC24MBoxType* type) {
|
||||
u32 msgType = msg->data[1];
|
||||
if (msgType & 0x10)
|
||||
*type = NWC24_MBOX_TYPE_SEND;
|
||||
else if (msg->type & 0x20)
|
||||
else if (msgType & 0x20)
|
||||
*type = NWC24_MBOX_TYPE_RECV;
|
||||
else
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
@@ -32,7 +33,8 @@ NWC24Err NWC24ReadMsgField(const NWC24MsgObj* msg, char* fieldName, u8* output,
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
type = NWC24_MBOX_TYPE_SEND;
|
||||
result = SelectMBox(msg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
@@ -75,7 +77,8 @@ NWC24Err NWC24ReadMsgFaceData(const NWC24MsgObj* msg, u8* faceData) {
|
||||
char* buffer;
|
||||
u32 length;
|
||||
NWC24Err result;
|
||||
if ((privateMsg->type & 2) && !(privateMsg->type & 0x1000))
|
||||
u32 msgType = privateMsg->type;
|
||||
if ((msgType & 2) && !(msgType & 0x1000))
|
||||
return NWC24_ERR_NOT_FOUND;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
@@ -282,7 +285,7 @@ NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacit
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
if (!(privateMsg->type & 2))
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
result = SelectMBox(msg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
@@ -321,7 +324,8 @@ NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 capacity
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
type = NWC24_MBOX_TYPE_SEND;
|
||||
result = SelectMBox(msg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
@@ -400,7 +404,7 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
|
||||
return NWC24_ERR_PROTECTED;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
*encoding = 0;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
result = SelectMBox(msg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
@@ -408,13 +412,12 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
|
||||
return result;
|
||||
}
|
||||
length = privateMsg->textSize;
|
||||
if (length == 0)
|
||||
length = privateMsg->text.size;
|
||||
length = length != 0 ? length : privateMsg->text.size;
|
||||
if (length == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
if (length > capacity - 1) {
|
||||
overflow = NWC24_ERR_OVERFLOW;
|
||||
length = capacity - 1;
|
||||
overflow = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
|
||||
switch (result) {
|
||||
@@ -453,8 +456,10 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
|
||||
case 2:
|
||||
decodedSize = 0;
|
||||
result = ReadBase64Data(&file, &privateMsg->text, (u8*)text, length, &decodedSize);
|
||||
if (result == NWC24_OK && decodedSize != privateMsg->textSize)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
if (result == NWC24_OK) {
|
||||
if (decodedSize != privateMsg->textSize)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
}
|
||||
text[length] = 0;
|
||||
break;
|
||||
case 3:
|
||||
@@ -479,15 +484,16 @@ NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
NWC24File file;
|
||||
NWC24MBoxType type;
|
||||
u32 decodedSize;
|
||||
NWC24Err result, closeResult;
|
||||
u32 decodedSize;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
if (index >= privateMsg->numAttached)
|
||||
return NWC24_ERR_NOT_FOUND;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
type = NWC24_MBOX_TYPE_SEND;
|
||||
result = SelectMBox(msg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
@@ -505,11 +511,9 @@ NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32
|
||||
}
|
||||
decodedSize = 0;
|
||||
result = ReadBase64Data(&file, &privateMsg->attached[index], output, capacity, &decodedSize);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
if (decodedSize != privateMsg->attachedSize[index]) { result = NWC24_ERR_FORMAT; }
|
||||
break;
|
||||
default: break;
|
||||
if (result == NWC24_OK) {
|
||||
if (decodedSize != *(u32*)((u8*)privateMsg->attachedSize + index * 4))
|
||||
result = NWC24_ERR_FORMAT;
|
||||
}
|
||||
closeResult = NWC24iMBoxCloseMsg(&file);
|
||||
if (result == NWC24_OK)
|
||||
|
||||
@@ -67,6 +67,8 @@ NWC24Err NWC24ReadMsgSubjectPublic(const NWC24MsgObj* msg, u16* subject, u32* su
|
||||
decodedCapacity = workSize - workHalf;
|
||||
result = NWC24GetMsgSubjectSize(msg, &subjectDataSize);
|
||||
switch (result) {
|
||||
default:
|
||||
goto done;
|
||||
case NWC24_OK:
|
||||
if (subjectDataSize > workHalf) {
|
||||
subjectDataSize = workHalf;
|
||||
@@ -77,7 +79,7 @@ NWC24Err NWC24ReadMsgSubjectPublic(const NWC24MsgObj* msg, u16* subject, u32* su
|
||||
if (result == NWC24_ERR_OVERFLOW) {
|
||||
truncated = TRUE;
|
||||
} else {
|
||||
goto done;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
charsetBuffer = NWC24WorkP->stringWork;
|
||||
@@ -87,7 +89,7 @@ NWC24Err NWC24ReadMsgSubjectPublic(const NWC24MsgObj* msg, u16* subject, u32* su
|
||||
if (result == NWC24_ERR_OVERFLOW) {
|
||||
truncated = TRUE;
|
||||
} else {
|
||||
goto done;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
*subjectSize = originalSize;
|
||||
@@ -104,8 +106,6 @@ NWC24Err NWC24ReadMsgSubjectPublic(const NWC24MsgObj* msg, u16* subject, u32* su
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,8 @@ NWC24Err NWC24ReadMsgTextPublic(const NWC24MsgObj* msg, u16* text, u32* textSize
|
||||
} else {
|
||||
result = NWC24GetMsgTextSize(msg, &textDataSize);
|
||||
switch (result) {
|
||||
default:
|
||||
goto done;
|
||||
case NWC24_OK:
|
||||
if (textDataSize > workSize) {
|
||||
textDataSize = workSize;
|
||||
@@ -141,10 +143,11 @@ NWC24Err NWC24ReadMsgTextPublic(const NWC24MsgObj* msg, u16* text, u32* textSize
|
||||
charsetBuffer = NWC24WorkP->stringWork + 0x20;
|
||||
result = NWC24ReadMsgTextEx(msg, (char*)work, textDataSize, charsetBuffer, 0x40);
|
||||
if (result != NWC24_OK) {
|
||||
if (result != NWC24_ERR_OVERFLOW) {
|
||||
goto done;
|
||||
if (result == NWC24_ERR_OVERFLOW) {
|
||||
truncated = TRUE;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
truncated = TRUE;
|
||||
}
|
||||
|
||||
*textSize = originalSize;
|
||||
@@ -153,8 +156,6 @@ NWC24Err NWC24ReadMsgTextPublic(const NWC24MsgObj* msg, u16* text, u32* textSize
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,8 +231,8 @@ done:
|
||||
|
||||
NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, const u16* text, u32 textSize,
|
||||
NWC24EncodingRegion region, u16 alternative, u8* work, u32 workSize) {
|
||||
char* stringWork;
|
||||
NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
|
||||
NWC24Work* nwcWork;
|
||||
u32 textSourceSize;
|
||||
u32 textWorkSize;
|
||||
BOOL is7Bit;
|
||||
@@ -262,22 +263,22 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u
|
||||
goto done;
|
||||
}
|
||||
|
||||
nwcWork = NWC24WorkP;
|
||||
result = NWC24iDetectEncodingToSend(nwcWork->stringWork, 0x40, subject, subjectSize, text, textSize, region);
|
||||
stringWork = NWC24WorkP->stringWork;
|
||||
result = NWC24iDetectEncodingToSend(stringWork, 0x40, subject, subjectSize, text, textSize, region);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
if (NWC24ParseCharsetStr(&charset, nwcWork->stringWork) != NWC24_OK) {
|
||||
if (NWC24ParseCharsetStr(&charset, stringWork) != NWC24_OK) {
|
||||
charset = 0;
|
||||
}
|
||||
textWorkSize = (workSize * textSize) / (textSize + subjectSize * 4);
|
||||
subjectWorkSize = workSize - textWorkSize;
|
||||
subjectWork = work + textWorkSize;
|
||||
textSourceSize = textSize;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &textWorkSize, text, &textSourceSize, nwcWork->stringWork, 0x40, region, alternative);
|
||||
result = NWC24iConvertFromInternalEncoding(work, &textWorkSize, text, &textSourceSize, stringWork, 0x40, region, alternative);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
@@ -285,7 +286,7 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = ENCIs7BitEncoding(&is7Bit, nwcWork->stringWork);
|
||||
result = ENCIs7BitEncoding(&is7Bit, stringWork);
|
||||
if (!is7Bit || (result != ENC_OK)) {
|
||||
switch (region) {
|
||||
case 0:
|
||||
@@ -314,7 +315,7 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u
|
||||
goto done;
|
||||
}
|
||||
if (charset == 0) {
|
||||
result = NWC24iSetMsgSubjectPlain(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork);
|
||||
result = NWC24iSetMsgSubjectPlain(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, stringWork);
|
||||
goto done;
|
||||
}
|
||||
switch (region) {
|
||||
@@ -334,10 +335,10 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u
|
||||
break;
|
||||
}
|
||||
if (result == 3) {
|
||||
result = NWC24iSetMsgSubjectQP(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork);
|
||||
result = NWC24iSetMsgSubjectQP(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, stringWork);
|
||||
} else {
|
||||
result =
|
||||
NWC24iSetMsgSubjectBase64(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork);
|
||||
NWC24iSetMsgSubjectBase64(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, stringWork);
|
||||
}
|
||||
|
||||
done:
|
||||
@@ -817,60 +818,63 @@ done:
|
||||
NWC24Err NWC24iSetMsgSubjectBase64(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName) {
|
||||
u32 workHalf;
|
||||
u32 secondSize;
|
||||
u8* second;
|
||||
u32 secondSize;
|
||||
u32 convertedLength;
|
||||
u32 subjectLength;
|
||||
u32 outputLength;
|
||||
u32 lineLength;
|
||||
u32 sourceOffset;
|
||||
u32 outputLength;
|
||||
u32 total;
|
||||
u32 charsetLength;
|
||||
NWC24Err result;
|
||||
|
||||
workHalf = workSize >> 1;
|
||||
secondSize = workSize - workHalf;
|
||||
second = work + workHalf;
|
||||
secondSize = workSize - workHalf;
|
||||
charsetLength = strlen(charsetName);
|
||||
lineLength = ((0x36 - charsetLength) * 3) >> 2;
|
||||
if (lineLength > workHalf) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
} else {
|
||||
workHalf = lineLength + 1;
|
||||
subjectLength = subjectSize;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &workHalf, subject, &subjectLength, charsetName, 0x40, region, alternative);
|
||||
switch (result) { case NWC24_OK: case NWC24_ERR_OVERFLOW: break; default: goto done; }
|
||||
result = NWC24EncodeWord(second, secondSize, &outputLength, charsetName, 0x40, 'B', work, workHalf - 1);
|
||||
switch (result) { case NWC24_OK: break; default: goto done; }
|
||||
{
|
||||
sourceOffset = subjectLength;
|
||||
if (sourceOffset == subjectSize) {
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, outputLength - 1);
|
||||
} else {
|
||||
charsetLength = strlen(charsetName);
|
||||
lineLength = (((0x3E - charsetLength) * 3) >> 2) + 1;
|
||||
total = outputLength - 1;
|
||||
for (; sourceOffset < subjectSize; sourceOffset += subjectLength) {
|
||||
subjectLength = subjectSize - sourceOffset;
|
||||
workHalf = lineLength;
|
||||
if (secondSize - total < 3) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
second[total++] = '\r';
|
||||
second[total++] = '\n';
|
||||
second[total++] = ' ';
|
||||
result = NWC24iConvertFromInternalEncoding(work, &workHalf, subject + sourceOffset, &subjectLength, charsetName, 0x40, region,
|
||||
alternative);
|
||||
switch (result) { case NWC24_OK: case NWC24_ERR_OVERFLOW: break; default: goto done; }
|
||||
result = NWC24EncodeWord(second + total, secondSize - total, &outputLength, charsetName, 0x40, 'B', work, workHalf - 1);
|
||||
switch (result) { case NWC24_OK: break; default: goto done; }
|
||||
total = total + outputLength - 1;
|
||||
}
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, total);
|
||||
}
|
||||
}
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
convertedLength = lineLength + 1;
|
||||
subjectLength = subjectSize;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &convertedLength, subject, &subjectLength, charsetName, 0x40, region, alternative);
|
||||
if (!(result == NWC24_OK || result == NWC24_ERR_OVERFLOW)) {
|
||||
return result;
|
||||
}
|
||||
result = NWC24EncodeWord(second, secondSize, &outputLength, charsetName, 0x40, 'B', work, convertedLength - 1);
|
||||
if (result != NWC24_OK) {
|
||||
return result;
|
||||
}
|
||||
sourceOffset = subjectLength;
|
||||
if (sourceOffset == subjectSize) {
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, outputLength - 1);
|
||||
} else {
|
||||
charsetLength = strlen(charsetName);
|
||||
lineLength = (((0x3E - charsetLength) * 3) >> 2) + 1;
|
||||
total = outputLength - 1;
|
||||
for (; sourceOffset < subjectSize; sourceOffset += subjectLength) {
|
||||
subjectLength = subjectSize - sourceOffset;
|
||||
convertedLength = lineLength;
|
||||
if (secondSize - total < 3) {
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
second[total++] = '\r';
|
||||
second[total++] = '\n';
|
||||
second[total++] = ' ';
|
||||
result = NWC24iConvertFromInternalEncoding(work, &convertedLength, subject + sourceOffset, &subjectLength, charsetName, 0x40,
|
||||
region, alternative);
|
||||
if (!(result == NWC24_OK || result == NWC24_ERR_OVERFLOW)) {
|
||||
return result;
|
||||
}
|
||||
result = NWC24EncodeWord(second + total, secondSize - total, &outputLength, charsetName, 0x40, 'B', work, convertedLength - 1);
|
||||
if (result != NWC24_OK) {
|
||||
return result;
|
||||
}
|
||||
total += outputLength - 1;
|
||||
}
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, total);
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"""Compact function diff with context: python ctxdiff.py <unit> <symbol> [--full]"""
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, "/home/cole/projects/tests")
|
||||
sys.path.insert(0, "/home/ubuntu/projects/tests")
|
||||
from odiff import dis, sym
|
||||
import os
|
||||
import itertools
|
||||
|
||||
@@ -9,3 +9,282 @@
|
||||
- NWC24CommitMsgInternal/WriteMIMEAttachHeader: ndiff-0, residual fuzzy from one r23<->r24 home swap at ~0x770 (cascade from earlier live range).
|
||||
- NWC24MsgSubject fns: reg-name/arg-staging diffs only; ReadMsgSubjectPublic missing `mr r8,r26` staging; iSetMsgSubjectBase64 +12 same-stream.
|
||||
- ConvertDaysToDate: 57 regname diffs + one extra tail block (`*month++` + b) vs orig's fall-through return.
|
||||
|
||||
## Wave 8 (agent/w0929/nwc24 post-veto)
|
||||
|
||||
- Veto compliance: `volatile u32 type` member gate REMOVED from NWC24MsgObj.h.
|
||||
MsgRead 14/16 -> 11/16 (orchestrator-accepted: CSE wall documented, no legal barrier).
|
||||
- SelectMBox TBAA-pair experiment (SelectMBox(NWC24MsgObj*) reading data[1]):
|
||||
committed as 6d3792ef but claims diffs-0 were wrong - loads STILL merge
|
||||
(verified ReadMsgField 101/102). Confirms MWCC load-RLE is type-insensitive/
|
||||
address-keyed: provably-same address merges regardless of struct member path.
|
||||
- MBoxCheck store-forward: 3 forms tried. Struct+out-param: `stw` kept, reload
|
||||
forwarded (-1). Plain locals: promoted entirely (-2). `*idp` read: same.
|
||||
Base's `stw r0,8(r1); lwz r4,8(r1)` requires producer-reg != consumer-reg AND
|
||||
no fold - pure scheduling, no source lever found.
|
||||
- UpdateDlTask 249/253: base saves r28-r31 MANUALLY (interleaved `stw`+`mr`),
|
||||
mine pins r27-r31 -> `_savegpr_27`. Extra pinned reg = second workP temp
|
||||
(r27 vs r28 reuse). Removing `taskId` local didn't drop a reg. Documented
|
||||
manual-vs-savegpr family.
|
||||
- DecodeMIMEHeaderFieldBody lever confirmed: local mutation copies keep args
|
||||
unpinned (95.76).
|
||||
|
||||
## Wave 9 (agent/w0929/nwc24)
|
||||
|
||||
- MBoxCheck store-forward: 6 alias-provenance forms tried (whole-struct escape
|
||||
via named MBCOldestMsg + &mailbox arg, return-value getter + member
|
||||
assign/read, *idp read, box-> member access, header->oldestId re-derive).
|
||||
ALL still forward: MWCC coalesces the producing load into the arg reg (r4)
|
||||
whenever the value flows to the call. Base's `stw r0,8(r1); lwz r4,8(r1)`
|
||||
requires producer != arg reg - pure scheduling, exhausted.
|
||||
- PurgeOldestDlTask: state-init store-order cracked - orig assigns
|
||||
`comparisonValue, selectedValue, sortMode, comparisonId, initialized, valid`
|
||||
(member-init ORDER moves MWCC's stw emission order). Dropped `selectedId`
|
||||
copy. Tail remains r5 result-carrier + r30/r31 window swap (-6, same family).
|
||||
- RemoveDlTask block-form tail (`if (result >= OK) {id=0xffff}`) REGRESSED
|
||||
both callers - early-return form is correct.
|
||||
- ManageDlTaskListForMenu: RemoveDlTask(taskPointer) var reuse +1.
|
||||
- SetDlTaskAccessTime: hand-rolled -3/-9 chain replaced with shared
|
||||
ValidateDlTask(dlTask, FALSE) - identical chain shape, plausible orig reuse.
|
||||
- UpdateDlTask 249/253: base pins r28-r31 with MANUAL stw saves (interleaved
|
||||
mr r31,r3) not _savegpr_28; mine pins r27-r31 -> _savegpr_27. Epilogue-
|
||||
restructure attempts didn't change the save decision (manual-vs-savegpr
|
||||
is driven by pin count + mwcc internal cost model).
|
||||
- CheckDlHeaderConsistency 212/212 = mr-emit-order only (addi r31 first).
|
||||
- DecodeWord 181/180: base's loop = single offset counter + `add` recompute
|
||||
(pos never materialized as IV); mine gets pos-walking + counter (2 incrs).
|
||||
FindMarker-call, plain-recompute, pos-var forms all strength-reduce under
|
||||
this fn's register pressure. Documented SR wall.
|
||||
|
||||
## wave 10 findings (FindMarker materialization, ptr-arith inlining)
|
||||
|
||||
- **pos-local lever (proven)**: orig's `FindMarker` materializes `char* pos = input + offset`
|
||||
per iteration — MWCC pins pos to a callee reg across the strncmp call (`add rN,in,off;
|
||||
mr r3,rN; bl`). A recompute-in-arg form (`strncmp(input+offset,...)`) makes pos
|
||||
transient in r3 and loses the callee pin. Returning `input + offset` (recomputed)
|
||||
rather than `pos` matches base's site-dependent IV choice (counter+recompute at
|
||||
low-pressure sites, dual walking-pos+counter at high-pressure sites — MWCC picks
|
||||
per inlining context, same source).
|
||||
- **`start + 1` exprs (proven)**: orig's ExtractEncodedText never mutates `start` —
|
||||
every use is `start + 1` (`end = FindMarker(start + 1, ...)`, `length = end - (start + 1)`,
|
||||
decode args `(u8*)(start + 1)`). A `start++` mutation pins a dead extra callee reg
|
||||
and changes the inlined-FindMarker arg from `addi (start+off),1` recompute to
|
||||
walking. Closed 134/135 -> 135/135 (remaining = reg renames + _savegpr window).
|
||||
- **Redundant guard (proven)**: base emits `cmpwi end,0; beq skip` before the tail
|
||||
`*encodedSizeOut` write even though `end` was NULL-checked earlier — orig's
|
||||
source has a defensive `if (end != NULL)` MWCC can't fold (no cross-BB proof).
|
||||
- **Arg-check elision**: orig's ExtractEncodedText does NOT check `decoded == NULL`
|
||||
(checks encoded, decodedSize, encodedSizeOut only).
|
||||
- ConvertDateToDays tail: two magic-divide chains share the 0x51EB851F constant;
|
||||
base's scheduler emits `lis+addi` magic before the +299/-1 numerators, mine
|
||||
interleaves — pure DAG-schedule order, stmt reorder no-op (verified).
|
||||
- QDecode/CheckMsgBoxSpace/ConvertDaysToDate: insn-equal pin-window swaps +
|
||||
unrolled-loop scheduling permutation — documented tie-break families.
|
||||
- EncodeWord: base pins stack-arg (decodedSizeOut, 0x48(r1)) to r31 AND
|
||||
re-materializes string addrs per-site into arg regs; mine CSEs addrs into
|
||||
callee regs (competes for the same window). Whole-fn pin-order wall.
|
||||
|
||||
## wave 11 findings (asymmetric-access CSE-frontier break)
|
||||
|
||||
- **Asymmetric-access lever (proven, NWC24ReadMsgAttached)**: when two identical
|
||||
`arr[index]` accesses get CSE'd at the ADDRESS level (MWCC pins `base+idx*4`
|
||||
once, single `lwz` + reuse — one insn short of base's scaled-index +
|
||||
`add`/`lwz` recompute), phrase the second access through a different-but-equal
|
||||
expression so `index*4` is the ONLY shared CSE node: member-index form for one
|
||||
site, `*(u32*)((u8*)obj->arr + index*4)` for the other. The scaled index then
|
||||
wins the pin and each site recomputes `add` + `lwz disp` — base's exact form.
|
||||
Member-index on one side + byte-cast on the other = no shared address node.
|
||||
- Failed variants on the same wall: uniform member-index twice (addr pinned),
|
||||
`u32* sizePtr` local (materializes base -> `lwzx`), uniform byte-cast twice
|
||||
(addr pinned), `index *= 4` split-if (breaks single shared -5 tail block).
|
||||
- TextInternal -1 confirmed = SelectMBox type-reload CSE wall + beq/bne polarity;
|
||||
Attached -1 same wall. All other remaining diffs insn-equal renames.
|
||||
|
||||
## wave 12 findings (arg-reg pinning model, PurgeOldestDlTask 170->175)
|
||||
|
||||
- **Scoped-pointer arg-pin (proven)**: when an inline helper's pointer param is
|
||||
shared across phases, declaring a scoped local per phase makes MWCC
|
||||
re-materialize `&obj` into the arg reg per phase instead of pinning one callee
|
||||
reg — this cascades the result var into the NEXT arg reg (r5), matching base.
|
||||
`readTask = &task` scoped to read phase + `&task` fresh at the remove call:
|
||||
dlTask->r3, dlHead->r4, err->r5 = base's exact arg-register carrier model.
|
||||
- **Separate-ifs double-assign (proven)**: `if (result < 0) { err = result; }
|
||||
if (result >= 0) { err = result; write }` keeps BOTH `mr` emits; the if/else
|
||||
form folds them (GVN). Two separate ifs share the compare but keep per-edge
|
||||
assigns.
|
||||
- **`else { return x }` unfuses the branch**: `if (c) { X } else { return x }`
|
||||
emits `b exit` on the else path where bare `if (c) {X}` fused `blt` — matches
|
||||
base's bge+ b layout piece.
|
||||
- ManageDlTaskListForMenu reached insn-equal 152/152 via `&task` at both calls
|
||||
(no pointer var at all) — MWCC's phase model gives arg-reg materialization.
|
||||
- Remaining PurgeOldest -1: base's dead `cmpwi err,0; mr r3,err; bge;b` tail —
|
||||
a folded `if(err>=0) return; return` that MWCC won't re-emit from source.
|
||||
|
||||
## wave 13 findings (index-IV recompute, store-forward ordering)
|
||||
|
||||
- **Index-IV + recompute lever (proven, DecodeWord 181->180 insn-equal)**:
|
||||
pointer-walk IVs (`pos++` + separate count) cost a dual increment; orig used
|
||||
`for (i...) { pos = start + i; ... }` — single index IV, pointer recomputed
|
||||
per iteration as `add r31,base,idx`. Rewrite `ptr++`-walks as indexed recompute
|
||||
when base shows `add rX,base,rI` inside the loop.
|
||||
- **MBoxCheck store-forward narrowed to scheduling**: baseline (struct
|
||||
{oldestId, header} + u32* getter + member read) now emits
|
||||
`lwz r4,0x20(r4); stw r4,8` — MWCC binds the RHS load straight into the arg
|
||||
reg. Base binds it to r0 (scratch) then `stw;lwz` — an arg-marshal schedule
|
||||
where r4 was still busy. ~10 forms (void* getter, separate locals, punned
|
||||
reads, assignment-expr args) all forward the store. Wall: not a provenance
|
||||
issue, pure scheduling.
|
||||
- **EncodeWord result-carrier pin**: base carries `result` in r3 across
|
||||
appends (li r3,-8/-3/0); mine pins r31 (costs savegpr_21 vs _22 + renames).
|
||||
The -1 insn is the 4-char `||` chain's last-term polarity (bne-else vs
|
||||
beq-append); `&&` inversion emits identically.
|
||||
- **"?" literal via `li r4,reloc`**: base materializes short-string args via
|
||||
li+reloc inline (no pin); mine pinned r25 for it. Minor.
|
||||
|
||||
## wave 14 findings (orchestrator hints exhausted)
|
||||
|
||||
- **UpdateDlTask web-reduction**: tried hoisting `DlTaskListHeader* header` once
|
||||
(regressed 249->248 — added a web), dropping the `task` alias (identical),
|
||||
nested-ifs for the `write && !opened && !owner` chain (identical), flat
|
||||
4-term `&&` (identical). The 5th callee web is the second phase's workP-select
|
||||
rotator — the phases are disjoint so the webs can't merge; base's r28 reuse
|
||||
across phases is allocator color-choice, not a source-level merge. Wall stands.
|
||||
- **EncodeWord ||-chain polarity**: term reorder (`q` before `Q`), `!(x!=c)`
|
||||
last-term negation, `!(A||B||C||D)` guard-form inversion, else-folded
|
||||
`*encoded='\0'; goto done` — all emit the same `bne` last term or worse (+2
|
||||
for else-fold). The else-fall layout base shows requires the join be
|
||||
non-adjacent; MWCC's block order here isn't moved by source polarity.
|
||||
|
||||
## wave 15 findings
|
||||
|
||||
- **MsgRead CSE wall bypass (no volatile)**: `type = NWC24_MBOX_TYPE_SEND;`
|
||||
default-assign immediately before `SelectMBox(msg, &type)` folds to `li r5,0`
|
||||
in the out-reg and makes the fn insn-equal — ReadMsgField 102/102,
|
||||
ReadMsgSubject 82/82, ReadMsgAttached 91/91. FromAddr regressed +4
|
||||
(reverted — its -1 gap is the same double-load wall but the default's `li`
|
||||
doesn't balance there). NOTE: MWCC does NOT model the store as a clobber
|
||||
(folds the local's value through the call) — the win is insn-balance, not
|
||||
genuine CSE suppression; base still emits a real second `lwz`.
|
||||
- **CSE wall verified deeper**: base `NWC24ReadMsgField`/`FromAddr` show TWO
|
||||
`lwz 4(r27)` separated only by the bit-test error branch — no call, no store
|
||||
between them. The clobber-reproduction theory is dead for this pair; orig's
|
||||
suppression mechanism is still unknown (volatile decl vetoed).
|
||||
- **UpdateDlTask workP re-fetch**: `header` var fetched via GetCachedDlHeader
|
||||
+ re-fetched after validate2 is a dead-assign (eliminated, no web effect).
|
||||
`task`-alias drop, flat/nested && chains, early-return variants — all
|
||||
identical. The 5th callee web (phase-2 workP rotator, r27 vs base's r28
|
||||
reuse) is allocator coloring, not source-mergeable.
|
||||
- **RemoveDlTask caller-conflict**: NWC24DeleteDlTask's inline wants the
|
||||
single-check `if (result>=0) id=0xffff` form (base: one cmpwi + bge + sth),
|
||||
PurgeOldestDlTask wants separate-ifs (double `mr r5,r3` carrier copies).
|
||||
Separate-ifs wins the aggregate (175/176 + 108/105); single-if, early-return,
|
||||
and assign-then-if all regress both callers.
|
||||
|
||||
## wave 16 findings (CSE wall — final verdict)
|
||||
|
||||
- **The CSE is purely address-keyed**: EVERY same-address access path
|
||||
normalizes to the same VN and merges — `*((u32*)((u8*)msg+4))`,
|
||||
`*((s32*)msg+1)`, `*(&msg->data[1])`, SelectMBox taking
|
||||
`const NWC24MsgObjPrivate*` (`pmsg->type` member path), and a same-offset
|
||||
union member (`union { u32 type; u32 msgType; }` — caller reads ->type,
|
||||
SelectMBox reads ->msgType). All emit one `lwz` and merge.
|
||||
- **Bitfield does defeat it but wrong ops**: `u32 type : 20` member produced
|
||||
the fused-extract form (`rlwinm. r0,r3,0x14,bit; srwi r0,r3,0xc`) on ONE
|
||||
load — never a second lwz. `u32 type : 32` normalized to plain u32 (merge).
|
||||
A `union { u32 type; u32 typeBits : 20; }` keeps ->type clean for all other
|
||||
fns (FaceData stays diffs-0) but SelectMBox's read still fuses-extracts.
|
||||
- **Verdict**: only a true clobber or volatile breaks it (vetoed). Base's
|
||||
second `lwz` at a different code position with no intervening call/store
|
||||
means orig's suppression mechanism is internal to MWCC's block model —
|
||||
likely a load in a non-dominated sibling block orig emitted differently
|
||||
that we haven't found. Documented wall; committed form uses the
|
||||
`type = NWC24_MBOX_TYPE_SEND` default-assign (insn-equal, plausible orig
|
||||
idiom) for Field/Subject/Attached.
|
||||
|
||||
## Wave 17 — closest-flip sweep (blocking fns enumerated; all insn-equal ties)
|
||||
Blocking fns per unit (diff counts, all count-matched): MsgSubject — NWC24SetMsgSubjectAndTextPublic 65, NWC24iSetMsgSubjectQP 12, NWC24iSetMsgSubjectBase64 10. MsgCommit — NWC24CommitMsgInternal 18, CheckMsgBoxSpace 75, WriteMIMEAttachHeader 5. DateParser — NWC24iDateToOSCalendarTime 13, ConvertDateToDays 16, ConvertDaysToDate 79. MsgRead — NWC24ReadMsgTextInternal (insn-equal), NWC24ReadMsgFromAddr -1 (SelectMBox CSE wall), NWC24ReadMsgAttached -1 (same wall), NWC24ReadMsgMBRegDate/MBDelay/etc. diff 0.
|
||||
- WriteMIMEAttachHeader: 2-web home swap (type→r30/disp→r29 vs r29/r30) + assoc ((mime+disp)+type vs mime+(disp+type)). Tried: expr assoc reorder, decl reorder, stmt merge (+= into strlen expr → extra web, savegpr_25 vs _24, reverted). Wall: MWCC normalizes assoc; home assignment is allocator-internal.
|
||||
- iSetMsgSubjectBase64: arg-copy order — base pins work(r8)→r22 FIRST then r4..r7→r18..r21; mine arg-order. Web-creation order unmovable by: work-first stmt reorder, `second-work` re-derive (+1 insn, charset spilled), second-as-copy form. Second cluster: stack-reload scheduling (lwz r0/r3 + add order). Wall.
|
||||
- iDateToOSCalendarTime: year-web r0↔r5 + shared "0"-web (isLeapYear=0 / msec=0 / usec=0 coalesced) r5↔r0. Tried: isLeapYear init moved late (+1 insn), single-assign form (identical), interleaved-init (identical). Coloring tie.
|
||||
- ConvertDateToDays: magic-div interleave at tail — base materializes 0x51ec magic before yo+299; same insns, different operand emission/dest names. Scheduling tie.
|
||||
|
||||
## Wave 18 — smallest-blocker decode passes (no flips; all web-coloring ties)
|
||||
- WriteMIMEAttachHeader (5): base assoc = type+=enc in-place then disp+typeSum→r0, mime+that→r3. Tried chained accumulation (`disp += type`; mime+disp) → -1 insn + savegpr_25 (extra web, reverted); paren-isolated pair sum → same 5 diffs; decl/stmt orders → normalized. Residual = type/disp r29↔r30 home swap + assoc — allocator tie.
|
||||
- iSetMsgSubjectBase64 (10): arg-copy order r8→r22 first (web-creation order: work pinned earliest) + stack-reload scheduling. work-first stmt reorder normalized; `second-work` re-derive +1. Wall.
|
||||
- iSetMsgSubjectQP (12): single secondSize-web r30↔r31 swap vs stack-reloaded loop local. Init-order flip regressed to 17 (swap moved to different web pair) — reverted.
|
||||
- CommitMsgInternal (18): two web-permutation clusters (flag→r23/r28, stringWork→r24/r23, err→r28/r23) — whole-function coloring.
|
||||
- iDateToOSCalendarTime (13): year-web r0↔r5 vs coalesced "0"-web (isLeapYear/msec/usec share one li 0 web). 3 init-position variants tried — coloring tie.
|
||||
- ConvertDateToDays (16): magic-div const-materialization + interleave order at tail — scheduling tie.
|
||||
Verdict: remaining nwc24 diffs are all allocator/scheduler-internal homes; source levers (assoc, decl order, stmt order, init position, accumulation direction) have been exhausted across ~15 forms this wave.
|
||||
|
||||
## wave 19 — alias-decl lever transfer attempts (all failed, reverted)
|
||||
- CheckDlHeaderConsistency fix (wave prior): `DlTaskData* taskData = (DlTaskData*)&task` first decl -> diffs 0. Committed 2cf9bb4f.
|
||||
- IterateDlTask r6/r7: `NWC24Work* work = NWC24WorkP` top-init -> same 10; `entriesHeader = header` -> -1 insn (drops addi); early `entriesHeader = header` before work reload -> -1 + r0->r8 shift. Reverted.
|
||||
- iSetMsgSubjectBase64 arg-pin r8-first: stmt reorder `second` before `workHalf` -> same 10; initialized-first-decl `u8* second = work + (workSize>>1)` -> same 10. MWCC emits arg copies by internal order. Reverted.
|
||||
- InitDlTask 3-web rotation (zero->r28/r29, strtoul1, strtoul2): stmt swap strtoul order -> 32 (worse). Reverted.
|
||||
- DecodeWord 140 (whole-fn permutation): base _savegpr_18 (14 callee) vs mine _savegpr_19 (13) — base has ONE MORE pinned web. Its `?` delimiter loop: `li r22,0` IV + `add r31,r18,r22` (encoded + IV, index-form; no walking `current` pointer). Tried: `encoded+offset` from consumedSize (178/180 -2), `encoded+consumedSize+offset` (142, _savegpr_20), `scanStart` alias ptr (181/180 +1), decl-order swap (same), `encodedWordPosition+offset` consumedSize-init loop (178/180 -2). All reverted. Open question: how orig emits encoded+offset with consumedSize absorbed — IV web may be `consumedSize+offset` merged where init `li 0` contradicts; or the scan genuinely starts at encoded[0] (semantically suspect vs `=?` prefix at index 1).
|
||||
|
||||
## wave 20 — Mime mid-size fns (all insn-equal, no count-gaps)
|
||||
- CopyWithoutLinearWhiteSpaces 17->13: decl/init-order swap `u32 outputOffset` before `BOOL afterNewline` (committed). Remaining: flag->r11 vs r9, value->r9 vs r8, bound->r8 vs r11 — one extra pre-flag web in mine.
|
||||
- Failed there: `char value` top-decl / first-decl, `u32 capacity` (15), `capacity = *outputSize` at decl (16 — lwz hoists over flag init).
|
||||
- QDecode 25: input/output/counter trio r26-r28 rotation — base homes reversed creation order, allocator-internal.
|
||||
- ExtractEncodedText 13: per-inline FindMarker web numbering — markerLen/offset pairs swap r22<->r23 and r31<->r23 across the two inline sites.
|
||||
- DecodeMIMEHeaderFieldBody 41: arg cluster +1 shift (base r24-r27 consecutive vs mine r23,r24,r31,r25) + zero-web pinning (base re-materializes li r0/li r4 per store; mine shares r10/r30 webs). Same family as SetMsgSubjectAndTextPublic.
|
||||
- EncodeWord: rechecked — 51/51 diffs 0 for `NWC24EncodeWord` in Mime; earlier -1 was on a different EncodeWord symbol (MsgSubject path uses the Mime one — actually matching now).
|
||||
|
||||
## wave 21 — ExtractCharset pointer-walk mechanism decode
|
||||
- Base's 2nd scan is a WALKING pointer (`mr r3,r25` + `addi r25`) + separate offset counter (`addi r28`), vs mine index-form `add + addi r3,r3,2` per iter. Base materializes `start+2` callee-pinned (r25) as the FindMarker `input` arg web, dead-after -> MWCC folds `input+offset` to `input++`.
|
||||
- On-match recompute: base `add r3,start,offset` + `addi r0,r3,2` = orig's `input + offset` with `input`=`start+2` expr reassociated -> `(start+offset)+2`.
|
||||
- `end` NULL: base `li r0,0` on loop-fallthrough (FindMarker `return NULL`), not early init.
|
||||
- Variants tried: named `charsetStart` pin (82/84 -2, pins but still index-form — MWCC won't walk a named web), manual walking scan `for(...;scan++)` + `end=start+offset+2` recompute (84/84 insn-equal, RIGHT structure, 44d whole-fn scatter), goto fallthrough `end=NULL` (40d, +1 web savegpr_23), nested-if tail (83/84 -1), size-arg re-assoc `-2` forms (35d same).
|
||||
- UNRESOLVED: how to make MWCC materialize `start+2` as a dead-temp callee web that feeds BOTH the size-arg subf AND the inlined input (walk target). Committed FindMarker form stays at 35d.
|
||||
- Manual walking scan is a legitimate orig-plausible form (keep as fallback evidence) — its scatter was arg-window +1 shift, same family as everywhere.
|
||||
|
||||
## wave 22 — scoped-switch-result + post-loop-web arg experiments
|
||||
- CheckMsgBoxSpace: no error-return switch arms in the pfrest idiom sense — its switch assigns textSize per-arm then joins (already the join-consume shape). `textSize` uninit: no effect. 75d = duff-unrolled EstimateBase64Size interleave + savegpr_23v22 (+1 web wall).
|
||||
- ExtractCharset post-loop-web arg: `FindMarker(start+2,...)` IS the post-loop-web form — verified via full disasm that base's match-path recomputes `(start+offset)+2` (FindMarker `return input+offset` reassociated). The missing piece remains forcing `start+2` into a callee-pinned dead-temp; named pins don't walk, raw expr reassociates per-iter.
|
||||
- FindMarker `pos` removed (inline `input+offset` in strncmp arg): WORSE everywhere (ExtractEncodedText 13->49) — `pos` local is required, it's a real orig object.
|
||||
- ExtractEncodedText: `end` early-init (no change), buffer-end-subtraction size arg (16d, reverted).
|
||||
- QDecode: decl reorder (41d) + decl-init'd input/output (51d) both regress — early arg webs force different save window.
|
||||
- CopyWithoutLinearWhiteSpaces: value hoist/type/int-s32/u32/outputSize-deref/cap-expr — all no-op or worse; stays at committed 13d (vol home rotation r8-r11).
|
||||
- DecodeWord 140: same +1-callee-web wall (savegpr_19v18); base homes `encoded` at r18 (lowest pin) = longest-live web, needs one more pinned web than any source form produces.
|
||||
- CONFIRMED PATTERN: all remaining nwc24 fn-level diffs are web-home rotations where base pins exactly ONE more callee web (savegpr_N vs savegpr_N+1) or assigns arg-copy homes in a different order — allocator-internal, no source lever found across ~40 variants this session.
|
||||
|
||||
## wave 23 — in-loop-assignment + hold-live-across-call levers
|
||||
- FindMarker variants: `input++` walk-form (ExtractCharset 50, DecodeWord count-gap, ExtractEncodedText 46 — all regress; the dead-web SR won't fire through shared inline); `&start[2]` arg form (reassociates same).
|
||||
- DecodeWord: `wordBody` named local for encodedWordPosition+consumedSize (+1 insn), `encoded + encodedLength` shared-node (142, +1 web), `encodedWordPosition + encodedLength` arg (143), `encoded` direct in loop (142) — all regress vs committed 140. Base pins `encoded` at r18 (lowest pin, longest-live arg web); no source form reproduces the extra pinned web.
|
||||
- InitDlTask: `= ""` vs `= {0}` (same 31), byte-fill loop (166/144 count-gap — inline unroll is right).
|
||||
- IterateDlTask: `work = NWC24WorkP,` in-loop re-fetch (same 10 — hoists anyway).
|
||||
- Net: all remaining diffs confirmed as web-creation-order/home ties; no new lever landed this wave.
|
||||
|
||||
## wave 24 — decl-order + early-stmt-init levers (BIG WINS)
|
||||
- QDecode 25→0 (EXACT): `u8 value; u32 decodedOffset; u32 encodedOffset;` decl order (uninit) + early stmts `decodedOffset=0; value=0; result=NWC24_OK;` before checks + `for (encodedOffset = 0;` loop-IV. Mechanism: MWCC emits decl-inits eagerly in entry; uninit-decl + early-stmt gives base's exact emit order (dec@11, value@12, result@13, ptrs@33-34, enc@35) AND coloring (value-first decl rotated the home band).
|
||||
- FindMarker decl swap `s32 offset;` BEFORE `u32 markerLength` → ExtractEncodedText 13→0 (EXACT), ExtractCharset 35→27 (pinned-walk now matches), DecodeWord 140→142 (+2, acceptable trade).
|
||||
- SetMsgSubjectAndTextPublic 65d: base colors `stringWork` (lwz 0(0) = NWC24WorkP->stringWork offset-0 member) FIRST at r22 — decl perms/early-fetch all regress or no-op. Allocator ordering unshiftable.
|
||||
- InitDlTask 31d: zero-web r28↔r29 — base colors nwc24IdHigh first; decl-order inert (4 perms identical).
|
||||
- ExtractCharset `char* start2` block-scope → 82/84 count-gap (over-shares the walk web); reverted.
|
||||
|
||||
## wave-25 — pattern application to remaining ties (no wins)
|
||||
|
||||
Applied the early-stmt-init + decl-order + for-IV pattern to every directive target:
|
||||
|
||||
- **CopyWithoutLWS 13d**: value-hoist/top-decl/`u32 capacity`/`capacity-1` precompute — inert or worse (15/17). Committed s32-capacity form kept. Value↔cap-1↔outputOffset volatile rotation is allocator-internal.
|
||||
- **ExtractCharset 27d**: all 6 decl permutations inert. Decoded the walk: base's 2nd FindMarker runs `mr r3,r25` + `addi r25,r25,1` — the pinned `start+2` input web is MUTATED in-loop (IV-fold of `pos = input + offset` onto a dead-after pinned web). Match path recomputes `(start+offset)+2` (2 insns) vs mine's free pos web. A call-site-only `start2` local pins it and makes everything else structural-identical — but MWCC still chooses pos-recompute over the input++ fold. All input++/pos-walk source forms (`offset++,input++`, `pos++`) regress every other call site (ExtractEncodedText 0→47, DecodeWord count-gap) — committed index-form FindMarker is correct globally.
|
||||
- **DecodeMIMEBody 41d**: uniform +1 arg-window shift; base pins a zero web FIRST among callee webs (r23 for stb/stw zero-stores incl. the encodedSizeOut stack slot) — coloring not reachable via stmt/decl order.
|
||||
- **InitDlTask 31d**: r28↔r29 — base colors strtoul-result web before the {0}-store zero web; decl-order swaps, early-init stmts, store-order swap all inert. MWCC-internal web ordering.
|
||||
- **ConvertDateToDays 16d**: same tail = interleaved mulhw/mulli/srawi scheduling + operand-home choices on (yo+299)/(yo-1) magic-div chains.
|
||||
- **ConvertDaysToDate 79d**: whole-fn volatile-band rotation (base year→r10, magic→r9, temps→r7/r8; mine year→r7, magic→r10, temps→r8/r9).
|
||||
- **DateToOSCalendarTime 13d**: year-load web r5(base) vs r0(mine); named `u16 year` local, store reorder — inert or count-gap.
|
||||
- **CheckMsgBoxSpace 75d**: savegpr_22v23 (+1 callee web) — same universal wall; extra web isn't decl-reachable.
|
||||
|
||||
Confirmed again: the "+1 callee web" family and the zero-web-first coloring are allocator-internal decisions with no source-level lever found across ~20 variants this wave.
|
||||
|
||||
## wave-26 — smallest-first probes (no wins)
|
||||
|
||||
- **iSetMsgSubjectBase64 10d**: two residuals: (a) arg-save cluster order — base emits work's pinned copy (r22) SECOND after msg, before r4-r7 copies; mine emits r4-r8 in arg-index order. Tried: use-reorder (`second = work + (workSize>>1)` first), decl-init forms (`u8* second = work + workHalf`, `u32 workHalf = workSize >> 1`) — all inert. The copy order is MWCC-internal web numbering, not use/decl order. (b) tail: `total += outputLength - 1` vs `sourceOffset += subjectLength` interleave — scheduling only.
|
||||
- **iSetMsgSubjectQP 12d**: two-web r30↔r31 swap (secondSize vs a spilled workHalf reload). 3 decl-order variants — inert or worse.
|
||||
- **CommitMsgInternal 18d**: two identical blocks — flag-extract web (clrlwi/srwi) ↔ workP web swap r23/r24/r28. Same rotation family.
|
||||
- **ConvertDateToDays 16d**: reordered div operand defs 4 ways (commonLeapDays first, interleaved, split -=) — MWCC scheduler ignores source order for independent straight-line chains; inert or worse.
|
||||
- **DateToOSCalendarTime 13d**: (wave-25) year-load home r5 vs r0 — member-path/cast forms don't change web size/home.
|
||||
|
||||
Universal wall stands: web numbering/home-coloring driven by allocator-internal order, not reachable via decl order, use order, or stmt order.
|
||||
|
||||
Reference in New Issue
Block a user