Fixed incorrect string length being stored

This commit is contained in:
calcium 2024-08-24 23:43:47 -04:00
parent 76bf452547
commit 586b2912be

View File

@ -14,31 +14,34 @@ void ConstantPoolTags::ConstantPoolParser(ConstantPoolTags::Tags t, JavaClassFor
case Tags::Utf8: {
// std::cout << "FIXME: Implement Utf8 Constant Pool Tag" << std::endl;
ConstantUtf8Info ref;
std::vector<uint8_t> length = Utils::ReadFromStart(Globals::buffer(), 2);
ref.length = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer(), 2);
// std::vector<uint8_t> length = Utils::ReadFromStart(Globals::buffer(), 2);
ref.tag = t;
ref.length = Utils::vecToVal<uint16_t>(length);
// ref.length = Utils::vecToVal<uint16_t>(length);
unsigned char x = Utils::ReadFromStartIntoVal<unsigned char>(Globals::buffer(), 1);
bool valid = true;
ref.bytes = new unsigned char[ref.length.ToHostFormat()];
unsigned char* bytes = new unsigned char[ref.length.ToHostFormat()];
int len = 0;
for (int i = 0; i < ref.length.ToHostFormat(); i++)
{
if ((x & 0x80) == 0)
{
ref.bytes[i] = x;
bytes[i] = x;
}
else if ((x & 0x800) == 0)
{
unsigned char y = Utils::ReadFromStartIntoVal<unsigned char>(Globals::buffer(), 1);
ref.bytes[i] = ((x & 0x1f) << 6) + (y & 0x3f);
bytes[i] = ((x & 0x1f) << 6) + (y & 0x3f);
}
else if ((x & 0x10000) == 0)
{
unsigned char y = Utils::ReadFromStartIntoVal<unsigned char>(Globals::buffer(), 1);
unsigned char z = Utils::ReadFromStartIntoVal<unsigned char>(Globals::buffer(), 1);
ref.bytes[i] = ((x & 0xf) << 12) + ((y & 0x3f) << 6) + (z & 0x3f);
bytes[i] = ((x & 0xf) << 12) + ((y & 0x3f) << 6) + (z & 0x3f);
}
else
{
@ -46,11 +49,20 @@ void ConstantPoolTags::ConstantPoolParser(ConstantPoolTags::Tags t, JavaClassFor
exit(1);
}
if (i != ref.length.ToHostFormat() - 1)
if (i < ref.length.ToHostFormat() - 1)
x = Utils::ReadFromStartIntoVal<unsigned char>(Globals::buffer(), 1);
len += 1;
}
std::string bytes1;
bytes1.append(reinterpret_cast<const char*>(bytes), 0, len);
ref.bytes = bytes1;
jc.constant_pool.push_back(ref);
ref.length = len;
break;
}
case Tags::Integer: