integer oferflow, shift of negative value

This commit is contained in:
Nikita Edel 2026-03-11 00:26:31 +01:00
parent a006cc5aa0
commit dfb200d037
4 changed files with 13 additions and 6 deletions

View file

@ -1217,4 +1217,4 @@ void Recipes::buildRecipeIngredientsArray(void)
Recipy::INGREDIENTS_REQUIRED *Recipes::getRecipeIngredientsArray(void)
{
return m_pRecipeIngredientsRequired;
}
}

View file

@ -141,11 +141,14 @@ void ShapedRecipy::requires(INGREDIENTS_REQUIRED *pIngReq)
TempIngReq.iIngC=0;
TempIngReq.iType = ((width>2) ||(height>2))?RECIPE_TYPE_3x3:RECIPE_TYPE_2x2; // 3x3
// 3x3
// 4jcraft, genuinly what is this garbage code
TempIngReq.uiGridA = new unsigned int [9];
TempIngReq.iIngIDA= new int [9];
TempIngReq.iIngValA = new int [9];
TempIngReq.iIngAuxValA = new int [9];
// 4jcraft,yes, yes!!
// use winapi and inbetween use a cstd function u could have used!
ZeroMemory(TempIngReq.iIngIDA,sizeof(int)*9);
ZeroMemory(TempIngReq.iIngValA,sizeof(int)*9);
memset(TempIngReq.iIngAuxValA,Recipes::ANY_AUX_VALUE,sizeof(int)*9);
@ -162,7 +165,8 @@ void ShapedRecipy::requires(INGREDIENTS_REQUIRED *pIngReq)
if (expected!=NULL)
{
int iAuxVal = expected->getAuxValue();
TempIngReq.uiGridA[x+y*3]=expected->id | iAuxVal<<24;
//4jcraft, added cast to uint (shift of negativ num, undefined)
TempIngReq.uiGridA[x+y*3]=expected->id | (unsigned int) iAuxVal<<24;
bFound=false;
for(j=0;j<TempIngReq.iIngC;j++)
@ -227,4 +231,4 @@ ShapedRecipy *ShapedRecipy::keepTag()
{
_keepTag = true;
return this;
}
}

View file

@ -128,7 +128,8 @@ void ShapelessRecipy::requires(INGREDIENTS_REQUIRED *pIngReq)
if (expected!=NULL)
{
int iAuxVal = (*ingredient)->getAuxValue();
TempIngReq.uiGridA[iCount++]=expected->id | iAuxVal<<24;
//4jcraft, added cast to uint, shift of negative int is undefined
TempIngReq.uiGridA[iCount++]=expected->id | (unsigned int) iAuxVal<<24;
// 4J-PB - put the ingredients in boxes 1,2,4,5 so we can see them in a 2x2 crafting screen
if(iCount==2) iCount=3;
bFound=false;
@ -179,4 +180,4 @@ void ShapelessRecipy::requires(INGREDIENTS_REQUIRED *pIngReq)
delete [] TempIngReq.iIngValA;
delete [] TempIngReq.iIngAuxValA;
delete [] TempIngReq.uiGridA;
}
}

View file

@ -33,7 +33,9 @@ void Random::setSeed(__int64 s)
int Random::next(int bits)
{
seed = (seed * 0x5DEECE66DLL + 0xBLL) & ((1LL << 48) - 1);
// 4jcraft, cast to uint64_t for modulo arithmethic
// overflow of int undefined, and its guaranteed here.
seed = ((uint64_t) seed * 0x5DEECE66DLL + 0xBLL) & ((1LL << 48) - 1);
return (int)(seed >> (48 - bits));
}