mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-19 20:07:20 +00:00
s integer overflow, unsafe cast
This commit is contained in:
parent
a24f9f5a5e
commit
ed13020cf3
|
|
@ -631,9 +631,9 @@ std::vector<TickNextTickData> *ServerLevel::fetchTicksInChunk(LevelChunk *chunk,
|
||||||
std::vector<TickNextTickData> *results = new std::vector<TickNextTickData>;
|
std::vector<TickNextTickData> *results = new std::vector<TickNextTickData>;
|
||||||
|
|
||||||
ChunkPos *pos = chunk->getPos();
|
ChunkPos *pos = chunk->getPos();
|
||||||
int west = pos->x << 4;
|
int west = (unsigned) pos->x << 4;
|
||||||
int east = west + 16;
|
int east = west + 16;
|
||||||
int north = pos->z << 4;
|
int north =(unsigned) pos->z << 4;
|
||||||
int south = north + 16;
|
int south = north + 16;
|
||||||
delete pos;
|
delete pos;
|
||||||
|
|
||||||
|
|
@ -1461,4 +1461,4 @@ void ServerLevel::flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFoun
|
||||||
{
|
{
|
||||||
chunkMap->flagEntitiesToBeRemoved(flags, removedFound);
|
chunkMap->flagEntitiesToBeRemoved(flags, removedFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,11 +135,11 @@ MerchantRecipeList *MerchantRecipeList::createFromStream(DataInputStream *stream
|
||||||
|
|
||||||
void MerchantRecipeList::load(CompoundTag *tag)
|
void MerchantRecipeList::load(CompoundTag *tag)
|
||||||
{
|
{
|
||||||
ListTag<CompoundTag> *list = (ListTag<CompoundTag> *) tag->getList(L"Recipes");
|
ListTag<Tag> *list = tag->getList(L"Recipes");
|
||||||
|
|
||||||
for (int i = 0; i < list->size(); i++)
|
for (int i = 0; i < list->size(); i++)
|
||||||
{
|
{
|
||||||
CompoundTag *recipeTag = list->get(i);
|
CompoundTag *recipeTag = (CompoundTag*) list->get(i);
|
||||||
m_recipes.push_back(new MerchantRecipe(recipeTag));
|
m_recipes.push_back(new MerchantRecipe(recipeTag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -192,4 +192,4 @@ size_t MerchantRecipeList::size()
|
||||||
bool MerchantRecipeList::empty()
|
bool MerchantRecipeList::empty()
|
||||||
{
|
{
|
||||||
return m_recipes.empty();
|
return m_recipes.empty();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1342,13 +1342,15 @@ void Entity::saveWithoutId(CompoundTag *entityTag)
|
||||||
|
|
||||||
void Entity::load(CompoundTag *tag)
|
void Entity::load(CompoundTag *tag)
|
||||||
{
|
{
|
||||||
ListTag<DoubleTag> *pos = (ListTag<DoubleTag> *) tag->getList(L"Pos");
|
// 4jcraft changed c style cast of templated class
|
||||||
ListTag<DoubleTag> *motion = (ListTag<DoubleTag> *) tag->getList(L"Motion");
|
// to getting the actual type and casting when needed
|
||||||
ListTag<FloatTag> *rotation = (ListTag<FloatTag> *) tag->getList(L"Rotation");
|
ListTag<Tag> *pos = tag->getList(L"Pos");
|
||||||
|
ListTag<Tag> *motion = tag->getList(L"Motion");
|
||||||
|
ListTag<Tag> *rotation = tag->getList(L"Rotation");
|
||||||
|
|
||||||
xd = motion->get(0)->data;
|
xd = ((DoubleTag*)motion->get(0))->data;
|
||||||
yd = motion->get(1)->data;
|
yd = ((DoubleTag*)motion->get(1))->data;
|
||||||
zd = motion->get(2)->data;
|
zd = ((DoubleTag*)motion->get(2))->data;
|
||||||
|
|
||||||
if (abs(xd) > 10.0)
|
if (abs(xd) > 10.0)
|
||||||
{
|
{
|
||||||
|
|
@ -1363,12 +1365,12 @@ void Entity::load(CompoundTag *tag)
|
||||||
zd = 0;
|
zd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
xo = xOld = x = pos->get(0)->data;
|
xo = xOld = x = ((DoubleTag*)pos->get(0))->data;
|
||||||
yo = yOld = y = pos->get(1)->data;
|
yo = yOld = y = ((DoubleTag*)pos->get(1))->data;
|
||||||
zo = zOld = z = pos->get(2)->data;
|
zo = zOld = z = ((DoubleTag*)pos->get(2))->data;
|
||||||
|
|
||||||
yRotO = yRot = rotation->get(0)->data;
|
yRotO = yRot = ((FloatTag*)rotation->get(0))->data;
|
||||||
xRotO = xRot = rotation->get(1)->data;
|
xRotO = xRot = ((FloatTag*)rotation->get(1))->data;
|
||||||
|
|
||||||
fallDistance = tag->getFloat(L"FallDistance");
|
fallDistance = tag->getFloat(L"FallDistance");
|
||||||
onFire = tag->getShort(L"Fire");
|
onFire = tag->getShort(L"Fire");
|
||||||
|
|
|
||||||
|
|
@ -654,8 +654,8 @@ void RandomLevelSource::postProcess(ChunkSource *parent, int xt, int zt)
|
||||||
pprandom->setSeed(level->getSeed());
|
pprandom->setSeed(level->getSeed());
|
||||||
__int64 xScale = pprandom->nextLong() / 2 * 2 + 1;
|
__int64 xScale = pprandom->nextLong() / 2 * 2 + 1;
|
||||||
__int64 zScale = pprandom->nextLong() / 2 * 2 + 1;
|
__int64 zScale = pprandom->nextLong() / 2 * 2 + 1;
|
||||||
// 4jcraft added casts to u, holy moly, the getSeed is 64 bit and the result is 32...
|
// 4jcraft added casts to a higher int and unsigned
|
||||||
pprandom->setSeed((((uint64_t)(int64_t)xt * (uint64_t)(int64_t)xScale) + ((uint64_t)(int64_t)zt * (uint64_t)(int64_t)zScale)) ^ level->getSeed());
|
pprandom->setSeed((((uint64_t)xt * (uint64_t)xScale) + ((uint64_t)zt * (uint64_t)zScale)) ^ level->getSeed());
|
||||||
|
|
||||||
bool hasVillage = false;
|
bool hasVillage = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ LevelChunk *McRegionChunkStorage::load(Level *level, int x, int z)
|
||||||
{
|
{
|
||||||
// 4jcraft fixed cast from int to int64 and taking the mask of the upper bits
|
// 4jcraft fixed cast from int to int64 and taking the mask of the upper bits
|
||||||
// and cast to unsigned
|
// and cast to unsigned
|
||||||
__int64 index = ((uint64_t)(uint32_t)(x) << 32) | (((uint64_t)(uint32_t)(z)));
|
uint64_t index = ((uint64_t)(uint32_t)(x) << 32) | (((uint64_t)(uint32_t)(z)));
|
||||||
|
|
||||||
AUTO_VAR(it, m_entityData.find(index));
|
AUTO_VAR(it, m_entityData.find(index));
|
||||||
if(it != m_entityData.end())
|
if(it != m_entityData.end())
|
||||||
|
|
@ -237,7 +237,8 @@ void McRegionChunkStorage::saveEntities(Level *level, LevelChunk *levelChunk)
|
||||||
{
|
{
|
||||||
#ifdef SPLIT_SAVES
|
#ifdef SPLIT_SAVES
|
||||||
PIXBeginNamedEvent(0,"Saving entities");
|
PIXBeginNamedEvent(0,"Saving entities");
|
||||||
__int64 index = ((__int64)(levelChunk->x) << 32) | (((__int64)(levelChunk->z))&0x00000000FFFFFFFF);
|
// 4j added cast to unsigned and changed index to u
|
||||||
|
uint64_t index = ((uint64_t)(uint32_t)(levelChunk->x) << 32) | (((uint64_t)(uint32_t)(levelChunk->z)));
|
||||||
|
|
||||||
delete m_entityData[index].data;
|
delete m_entityData[index].data;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -432,7 +432,8 @@ void HellRandomLevelSource::postProcess(ChunkSource *parent, int xt, int zt)
|
||||||
pprandom->setSeed(level->getSeed());
|
pprandom->setSeed(level->getSeed());
|
||||||
__int64 xScale = pprandom->nextLong() / 2 * 2 + 1;
|
__int64 xScale = pprandom->nextLong() / 2 * 2 + 1;
|
||||||
__int64 zScale = pprandom->nextLong() / 2 * 2 + 1;
|
__int64 zScale = pprandom->nextLong() / 2 * 2 + 1;
|
||||||
pprandom->setSeed(((xt * xScale) + (zt * zScale)) ^ level->getSeed());
|
// 4jcraft added casts to a higher int and unsigned
|
||||||
|
pprandom->setSeed((((uint64_t)xt * (uint64_t)xScale) + ((uint64_t)zt * (uint64_t)zScale)) ^ level->getSeed());
|
||||||
|
|
||||||
netherBridgeFeature->postProcess(level, pprandom, xt, zt);
|
netherBridgeFeature->postProcess(level, pprandom, xt, zt);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,8 @@ void TheEndLevelRandomLevelSource::postProcess(ChunkSource *parent, int xt, int
|
||||||
pprandom->setSeed(level->getSeed());
|
pprandom->setSeed(level->getSeed());
|
||||||
__int64 xScale = pprandom->nextLong() / 2 * 2 + 1;
|
__int64 xScale = pprandom->nextLong() / 2 * 2 + 1;
|
||||||
__int64 zScale = pprandom->nextLong() / 2 * 2 + 1;
|
__int64 zScale = pprandom->nextLong() / 2 * 2 + 1;
|
||||||
pprandom->setSeed(((xt * xScale) + (zt * zScale)) ^ level->getSeed());
|
// 4jcraft added cast to higher int and unsigned
|
||||||
|
pprandom->setSeed((((uint64_t)xt * xScale) + ((uint64_t)zt * zScale)) ^ level->getSeed());
|
||||||
|
|
||||||
Biome *biome = level->getBiome(xo + 16, zo + 16);
|
Biome *biome = level->getBiome(xo + 16, zo + 16);
|
||||||
biome->decorate(level, pprandom, xo, zo); // 4J - passing pprandom rather than level->random here to make this consistent with our parallel world generation
|
biome->decorate(level, pprandom, xo, zo); // 4J - passing pprandom rather than level->random here to make this consistent with our parallel world generation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue