summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2015-01-22 13:45:40 +0100
committerIngo Huerner <ingo.huerner@xse.de>2015-01-22 13:45:40 +0100
commit84210e9a13cf8b6b7496d0ed1615377a142cfe53 (patch)
treefc7302cc63beda45b2e18d9e48831dbaad230d64
parent9b810c249128d4c9d593445c71e0cb0f42f9e749 (diff)
downloadpersistence-client-library-84210e9a13cf8b6b7496d0ed1615377a142cfe53.tar.gz
Update after static code analysis (Coverity https://scan.coverity.com/projects/301)
-rw-r--r--src/persistence_client_library_backup_filelist.c30
-rw-r--r--src/persistence_client_library_file.c3
-rw-r--r--src/persistence_client_library_handle.c68
-rw-r--r--src/persistence_client_library_prct_access.c14
-rw-r--r--src/persistence_client_library_tree_helper.c10
-rw-r--r--test/persistence_client_library_dbus_test.c3
6 files changed, 63 insertions, 65 deletions
diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c
index 68165b6..a419e42 100644
--- a/src/persistence_client_library_backup_filelist.c
+++ b/src/persistence_client_library_backup_filelist.c
@@ -69,10 +69,10 @@ static void fillFileBackupCharTokenArray(unsigned int customConfigFileSize, char
while(i < customConfigFileSize)
{
- if( ((unsigned int)(*tmpPointer) < 127)
- && ((unsigned int)*tmpPointer >= 0))
+ if( ((int)(*tmpPointer) < 127)
+ && ((int)*tmpPointer >= 0))
{
- if(1 != gCharLookup[(unsigned int)*tmpPointer])
+ if(1 != gCharLookup[(int)*tmpPointer])
{
*tmpPointer = 0;
@@ -116,7 +116,7 @@ static void createAndStoreFileNames()
item->key = pclCrc32(0, (unsigned char*)path, strlen(path));
// we don't need the path name here, we just need to know that this key is available in the tree
item->value = "";
- jsw_rbinsert(gRb_tree_bl, item);
+ (void)jsw_rbinsert(gRb_tree_bl, item);
free(item);
}
i+=1;
@@ -166,7 +166,7 @@ int readBlacklistConfigFile(const char* filename)
createAndStoreFileNames(); // create filenames and store them in the tree
- munmap(configFileMap, buffer.st_size);
+ (void)munmap(configFileMap, buffer.st_size);
close(fd);
}
@@ -278,11 +278,13 @@ void key_val_rel(void *p )
key_value_s* rel = NULL;
rel = (key_value_s*)p;
- if(rel->value != NULL)
- free(rel->value);
-
if(rel != NULL)
+ {
+ if(rel->value != NULL)
+ free(rel->value);
+
free(rel);
+ }
}
@@ -292,7 +294,7 @@ static int pclBackupDoFileCopy(int srcFd, int dstFd)
int rval = 0;
memset(&buf, 0, sizeof(buf));
- fstat(srcFd, &buf);
+ (void)fstat(srcFd, &buf);
rval = (int)sendfile(dstFd, srcFd, 0, buf.st_size);
// Reset file position pointer of destination file 'dstFd'
@@ -310,6 +312,7 @@ int pclCreateFile(const char* path, int chached)
int numTokens = 0, i = 0, validPath = 1;
int handle = -1;
+ thePath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
strncpy(thePath, path, DbPathMaxLen);
tokenArray[numTokens++] = strtok(thePath, delimiters);
@@ -340,7 +343,7 @@ int pclCreateFile(const char* path, int chached)
// create folders
strncat(createPath, "/", DbPathMaxLen-1);
strncat(createPath, tokenArray[i], DbPathMaxLen-1);
- mkdir(createPath, 0744);
+ (void)mkdir(createPath, 0744);
}
// finally create the file
strncat(createPath, "/", DbPathMaxLen-1);
@@ -522,9 +525,9 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
if(handle == -1) // if we are in an inconsistent state: delete file, backup and checksum
{
- remove(origPath);
- remove(backupPath);
- remove(csumPath);
+ (void)remove(origPath);
+ (void)remove(backupPath);
+ (void)remove(csumPath);
}
return handle;
@@ -559,6 +562,7 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const
{
int handle = -1;
char pathToCreate[DbPathMaxLen] = {0};
+ pathToCreate[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
strncpy(pathToCreate, dstPath, DbPathMaxLen);
handle = pclCreateFile(pathToCreate, 0);
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 956c8cc..d84b39d 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -216,6 +216,7 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
length = gWTPathPrefixSize;
}
+ fileSubPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
strncpy(fileSubPath, dbPath+length, DbPathMaxLen);
snprintf(backupPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupPostfix);
snprintf(csumPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupCsPostfix);
@@ -851,7 +852,7 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy)
struct stat buf;
memset(&buf, 0, sizeof(buf));
- fstat(defaultHandle, &buf);
+ (void)fstat(defaultHandle, &buf);
rval = sendfile(handle, defaultHandle, 0, buf.st_size);
if(rval != -1)
{
diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c
index b5be100..b88f065 100644
--- a/src/persistence_client_library_handle.c
+++ b/src/persistence_client_library_handle.c
@@ -369,17 +369,15 @@ void set_file_backup_status(int idx, int status)
FileHandleTreeItem_s* newItem = malloc(sizeof(FileHandleTreeItem_s));
if(newItem != NULL)
{
- if(newItem->value.payload != NULL)
- {
- memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+ memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
- newItem->key = idx;
- newItem->value.fileHandle.backupCreated = status;
+ newItem->key = idx;
+ newItem->value.fileHandle.backupCreated = status;
- jsw_rberase(gFileHandleTree, foundItem);
+ jsw_rberase(gFileHandleTree, foundItem);
+
+ jsw_rbinsert(gFileHandleTree, newItem);
- jsw_rbinsert(gFileHandleTree, newItem);
- }
free(newItem);
}
}
@@ -450,16 +448,13 @@ void set_file_cache_status(int idx, int status)
FileHandleTreeItem_s* newItem = malloc(sizeof(FileHandleTreeItem_s));
if(newItem != NULL)
{
- if(newItem->value.payload != NULL)
- {
- memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+ memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
- jsw_rberase(gFileHandleTree, foundItem);
+ jsw_rberase(gFileHandleTree, foundItem);
- newItem->key = idx;
- newItem->value.fileHandle.cacheStatus = status;
- jsw_rbinsert(gFileHandleTree, newItem);
- }
+ newItem->key = idx;
+ newItem->value.fileHandle.cacheStatus = status;
+ jsw_rbinsert(gFileHandleTree, newItem);
free(newItem);
}
}
@@ -529,16 +524,14 @@ void set_file_user_id(int idx, int userID)
FileHandleTreeItem_s* newItem = malloc(sizeof(FileHandleTreeItem_s));
if(newItem != NULL)
{
- if(newItem->value.payload != NULL)
- {
- memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+ memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+
+ jsw_rberase(gFileHandleTree, foundItem);
- jsw_rberase(gFileHandleTree, foundItem);
+ newItem->key = idx;
+ newItem->value.fileHandle.userId = userID;
+ jsw_rbinsert(gFileHandleTree, newItem);
- newItem->key = idx;
- newItem->value.fileHandle.userId = userID;
- jsw_rbinsert(gFileHandleTree, newItem);
- }
free(newItem);
}
}
@@ -738,16 +731,14 @@ void set_ossfile_file_path(int idx, char* file)
FileHandleTreeItem_s* newItem = malloc(sizeof(FileHandleTreeItem_s));
if(newItem != NULL)
{
- if(newItem->value.payload != NULL)
- {
- memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+ memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+
+ jsw_rberase(gFileHandleTree, foundItem);
- jsw_rberase(gFileHandleTree, foundItem);
+ newItem->key = idx;
+ newItem->value.fileHandle.filePath = file;
+ jsw_rbinsert(gFileHandleTree, newItem);
- newItem->key = idx;
- newItem->value.fileHandle.filePath = file;
- jsw_rbinsert(gFileHandleTree, newItem);
- }
free(newItem);
}
}
@@ -813,17 +804,14 @@ void set_ossfile_backup_status(int idx, int status)
FileHandleTreeItem_s* newItem = malloc(sizeof(FileHandleTreeItem_s));
if(newItem != NULL)
{
- if(newItem->value.payload != NULL)
- {
- memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
+ memcpy(newItem->value.payload , foundItem->value.payload, sizeof(FileHandleData_u) ); // duplicate value
- newItem->key = idx;
- newItem->value.fileHandle.backupCreated = status;
+ newItem->key = idx;
+ newItem->value.fileHandle.backupCreated = status;
- jsw_rberase(gFileHandleTree, foundItem);
+ jsw_rberase(gFileHandleTree, foundItem);
- jsw_rbinsert(gFileHandleTree, newItem);
- }
+ jsw_rbinsert(gFileHandleTree, newItem);
free(newItem);
}
}
diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c
index 57e6be5..92ba970 100644
--- a/src/persistence_client_library_prct_access.c
+++ b/src/persistence_client_library_prct_access.c
@@ -74,7 +74,13 @@ PersistenceRCT_e get_table_id(int ldbid, int* groupId)
int get_resource_cfg_table_by_idx(int i)
{
- return gResource_table[i];
+ int idx = -1;
+
+ if(i > 0 && i < PrctDbTableSize)
+ {
+ idx = gResource_table[i];
+ }
+ return idx;
}
@@ -87,7 +93,7 @@ void invalidate_resource_cfg_table(int i)
int get_resource_cfg_table(PersistenceRCT_e rct, int group)
{
- int arrayIdx = 0;
+ int arrayIdx = 0, rval = -1;
// create array index: index is a combination of resource config table type and group
arrayIdx = rct + group;
@@ -125,9 +131,11 @@ int get_resource_cfg_table(PersistenceRCT_e rct, int group)
gResourceOpen[arrayIdx] = 1 ;
}
}
+
+ rval = gResource_table[arrayIdx];
}
- return gResource_table[arrayIdx];
+ return rval;
}
diff --git a/src/persistence_client_library_tree_helper.c b/src/persistence_client_library_tree_helper.c
index dc84171..1a88056 100644
--- a/src/persistence_client_library_tree_helper.c
+++ b/src/persistence_client_library_tree_helper.c
@@ -73,10 +73,7 @@ void* fh_key_val_dup(void *p)
{
dst->key = src->key; // duplicate hash key
- if(dst->value.payload != NULL)
- {
- memcpy(dst->value.payload , src->value.payload, sizeof(FileHandleData_u) ); // duplicate value
- }
+ memcpy(dst->value.payload , src->value.payload, sizeof(FileHandleData_u) ); // duplicate value
}
return dst;
@@ -139,10 +136,7 @@ void* kh_key_val_dup(void *p)
{
dst->key = src->key; // duplicate hash key
- if(dst->value.payload != NULL)
- {
- memcpy(dst->value.payload , src->value.payload, sizeof(KeyHandleData_u) ); // duplicate value
- }
+ memcpy(dst->value.payload , src->value.payload, sizeof(KeyHandleData_u) ); // duplicate value
}
return dst;
}
diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c
index 1b83c34..ceac126 100644
--- a/test/persistence_client_library_dbus_test.c
+++ b/test/persistence_client_library_dbus_test.c
@@ -47,6 +47,9 @@ int main(int argc, char *argv[])
int ret = 0;
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+ (void)argc;
+ (void)argv;
+
printf("Dbus interface test application\n");
/// debug log and trace (DLT) setup