mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Refactor usages of sha256_str
- Pass the actual array size instead of using the constant. - Use the string length to write sha256 string to file.
This commit is contained in:
parent
9e4da2244a
commit
c0b5e8965e
|
@ -149,8 +149,8 @@ void InitAndroid()
|
|||
if(pIOR != NULL)
|
||||
{
|
||||
char aFileSHA[SHA256_MAXSTRSIZE];
|
||||
sha256_str(ShaAllFile, aFileSHA, SHA256_MAXSTRSIZE);
|
||||
io_write(pIOR, aFileSHA, SHA256_MAXSTRSIZE - 1);
|
||||
sha256_str(ShaAllFile, aFileSHA, sizeof(aFileSHA));
|
||||
io_write(pIOR, aFileSHA, str_length(aFileSHA));
|
||||
io_close(pIOR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ void ClearPixelsTile(uint8_t *pImg, int Width, int Height, int TileIndex)
|
|||
}
|
||||
}
|
||||
|
||||
void GetImageSHA256(uint8_t *pImgBuff, int ImgSize, int Width, int Height, char *pSHA256Str)
|
||||
void GetImageSHA256(uint8_t *pImgBuff, int ImgSize, int Width, int Height, char *pSHA256Str, size_t SHA256StrSize)
|
||||
{
|
||||
uint8_t *pNewImgBuff = (uint8_t *)malloc(ImgSize);
|
||||
|
||||
|
@ -68,7 +68,7 @@ void GetImageSHA256(uint8_t *pImgBuff, int ImgSize, int Width, int Height, char
|
|||
CopyOpaquePixels(pNewImgBuff, pImgBuff, Width, Height);
|
||||
SHA256_DIGEST SHAStr = sha256(pNewImgBuff, (size_t)ImgSize);
|
||||
|
||||
sha256_str(SHAStr, pSHA256Str, SHA256_MAXSTRSIZE * sizeof(char));
|
||||
sha256_str(SHAStr, pSHA256Str, SHA256StrSize);
|
||||
|
||||
free(pNewImgBuff);
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ int main(int argc, const char **argv)
|
|||
char aSHA256Str[SHA256_MAXSTRSIZE];
|
||||
// This is the important function, that calculates the SHA256 in a special way
|
||||
// Please read the comments inside the functions to understand it
|
||||
GetImageSHA256(pImgBuff, ImgSize, Width, Height, aSHA256Str);
|
||||
GetImageSHA256(pImgBuff, ImgSize, Width, Height, aSHA256Str, sizeof(aSHA256Str));
|
||||
|
||||
char aNewName[IO_MAX_PATH_LENGTH];
|
||||
int StrLen = str_format(aNewName, std::size(aNewName), "%s_cut_%s", pImgName, aSHA256Str);
|
||||
|
|
Loading…
Reference in a new issue