Set<TTest, tt0, tt16> 定義第 15、16 位元,ToInt() 應回傳 1<<15 = 32768、1<<16 = 65536,但第 16 位元實際回傳 16777216 (1<<24),多左移 8 位。
sysset.h 中 SetBase::Data 陣列大小計算錯誤,導致 ToInt() 迴圈處理額外 8 位元(1 byte)。
template<class T, unsigned char minEl, unsigned char maxEl>
class SetBase {
protected:
unsigned char Data[((((int)(maxEl/8))-((int)(minEl/8))+1) != 3)?
(((int)(maxEl/8))-((int)(minEl/8))+1) : 4]; // 條件判斷導致 maxEl=16 時大小為 4 而非 3
};
int ToInt() const {
int Result = 0;
for (int i = sizeof(Data)-1; i >= 0; i--) {
Result |= Data[i];
Result <<= (i * sizeof(unsigned char) * 8); // 多處理 1 byte 導致左移 8 位
}
return Result;
}
Data 陣列大小計算公式,移除錯誤的三元條件。