Skip to content

Commit

Permalink
Fix invalid casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Morlat committed Sep 3, 2024
1 parent 0b0b533 commit ce1e42a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions include/bctoolbox/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct bctbx_io_methods_t {
ssize_t (*pFuncRead)(bctbx_vfs_file_t *pFile, void *buf, size_t count, off_t offset);
ssize_t (*pFuncWrite)(bctbx_vfs_file_t *pFile, const void *buf, size_t count, off_t offset);
int (*pFuncTruncate)(bctbx_vfs_file_t *pFile, int64_t size);
int64_t (*pFuncFileSize)(bctbx_vfs_file_t *pFile);
ssize_t (*pFuncFileSize)(bctbx_vfs_file_t *pFile);
int (*pFuncSync)(bctbx_vfs_file_t *pFile);
int (*pFuncGetLineFromFd)(bctbx_vfs_file_t *pFile, char *s, int count);
bool_t (*pFuncIsEncrypted)(bctbx_vfs_file_t *pFile);
Expand Down Expand Up @@ -163,7 +163,7 @@ BCTBX_PUBLIC bctbx_vfs_file_t *bctbx_file_open2(bctbx_vfs_t *pVfs, const char *f
* @param pFile bctbx_vfs_file_t File handle pointer.
* @return BCTBX_VFS_ERROR if an error occured, file size otherwise.
*/
BCTBX_PUBLIC int64_t bctbx_file_size(bctbx_vfs_file_t *pFile);
BCTBX_PUBLIC ssize_t bctbx_file_size(bctbx_vfs_file_t *pFile);

/**
* Truncates/ Extends a file.
Expand Down
4 changes: 2 additions & 2 deletions src/vfs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ int bctbx_file_sync(bctbx_vfs_file_t *pFile) {
return ret;
}

int64_t bctbx_file_size(bctbx_vfs_file_t *pFile) {
int64_t ret = BCTBX_VFS_ERROR;
ssize_t bctbx_file_size(bctbx_vfs_file_t *pFile) {
ssize_t ret = BCTBX_VFS_ERROR;
if (pFile) {
if (bctbx_file_flush(pFile) < 0) {
return BCTBX_VFS_ERROR;
Expand Down
16 changes: 8 additions & 8 deletions src/vfs/vfs_encrypted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ const std::vector<uint8_t> &VfsEncryption::rawHeaderGet() const noexcept {
*/
void VfsEncryption::parseHeader() {
// check file exists
int64_t ret = bctbx_file_size(pFileStd); // bctbx_file_size return a signed value...
if (ret < baseFileHeaderSize) { // this is not an EVFS file, assume it is plain
mFileSize = ret; // set file size so we know that the file exists and is plain
ssize_t ret = bctbx_file_size(pFileStd); // bctbx_file_size return a signed value...
if (ret < (ssize_t)baseFileHeaderSize) { // this is not an EVFS file, assume it is plain
mFileSize = (uint64_t)ret; // set file size so we know that the file exists and is plain
m_module = nullptr;
return;
}
uint64_t fileSize = ret; // turn it into an unsigned one after checking it is >0.
uint64_t fileSize = (uint64_t)ret; // turn it into an unsigned one after checking it is >0.

// read the header
r_header = std::vector<uint8_t>(baseFileHeaderSize);
Expand Down Expand Up @@ -546,7 +546,7 @@ void VfsEncryption::writeHeader(bctbx_vfs_file_t *fp) {
int64_t VfsEncryption::fileSizeGet() const noexcept {
// plain file?
if (m_module == nullptr) {
return bctbx_file_size(pFileStd);
return (int64_t)bctbx_file_size(pFileStd);
}
return mFileSize;
}
Expand Down Expand Up @@ -892,11 +892,11 @@ static ssize_t bcWrite(bctbx_vfs_file_t *pFile, const void *buf, size_t count, o
* @param pFile File handle pointer.
* @return -errno if an error occurred, file size otherwise (can be 0).
*/
static int64_t bcFileSize(bctbx_vfs_file_t *pFile) {
int ret = BCTBX_VFS_ERROR;
static ssize_t bcFileSize(bctbx_vfs_file_t *pFile) {
ssize_t ret = BCTBX_VFS_ERROR;
if (pFile && pFile->pUserData) {
VfsEncryption *ctx = static_cast<VfsEncryption *>(pFile->pUserData);
return ctx->fileSizeGet();
return (ssize_t)ctx->fileSizeGet();
}
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vfs/vfs_standard.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static ssize_t bcWrite(bctbx_vfs_file_t *pFile, const void *buf, size_t count, o
* @param pFile File handle pointer.
* @return -errno if an error occurred, file size otherwise (can be 0).
*/
static int64_t bcFileSize(bctbx_vfs_file_t *pFile) {
static ssize_t bcFileSize(bctbx_vfs_file_t *pFile) {
int rc; /* Return code from fstat() call */
struct stat sStat; /* Output of fstat() call */
if (pFile == NULL || pFile->pUserData == NULL) return BCTBX_VFS_ERROR;
Expand All @@ -165,7 +165,7 @@ static int64_t bcFileSize(bctbx_vfs_file_t *pFile) {
if (rc != 0) {
return -errno;
}
return sStat.st_size;
return (ssize_t)sStat.st_size;
}

/*
Expand Down

0 comments on commit ce1e42a

Please sign in to comment.