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:
Robert Müller 2022-10-15 17:49:32 +02:00
parent 9e4da2244a
commit c0b5e8965e
2 changed files with 5 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -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);