diff --git a/meson.build b/meson.build index 49d4291b7..1545ecfec 100644 --- a/meson.build +++ b/meson.build @@ -40,6 +40,9 @@ endif #################################################################################################################################### # Enable as many additional warnings as possible to catch potential errors warning_enable = [ + # Warn whenever a pointer is cast so as to remove a type qualifier from the target type + '-Wcast-qual', + # Warn for implicit conversions that may alter a value '-Wconversion', diff --git a/src/build/common/xml.c b/src/build/common/xml.c index 56b239b6e..1e7d7fa24 100644 --- a/src/build/common/xml.c +++ b/src/build/common/xml.c @@ -23,7 +23,8 @@ xmlDocumentNewParam(const String *const rootNode, const XmlDocumentNewParam para if (param.dtdName != NULL) { ASSERT(param.dtdFile != NULL); - xmlCreateIntSubset(result->xml, (unsigned char *)strZ(param.dtdName), NULL, (unsigned char *)strZ(param.dtdFile)); + xmlCreateIntSubset( + result->xml, (const unsigned char *)strZ(param.dtdName), NULL, (const unsigned char *)strZ(param.dtdFile)); } FUNCTION_TEST_RETURN(XML_DOCUMENT, result); @@ -42,7 +43,7 @@ xmlNodeAttribute(const XmlNode *this, const String *name) ASSERT(name != NULL); String *result = NULL; - xmlChar *const value = xmlGetProp(this->node, (unsigned char *)strZ(name)); + xmlChar *const value = xmlGetProp(this->node, (const unsigned char *)strZ(name)); if (value != NULL) { @@ -67,7 +68,7 @@ xmlNodeAttributeSet(XmlNode *const this, const String *const name, const String ASSERT(name != NULL); ASSERT(value != NULL); - xmlSetProp(this->node, (unsigned char *)strZ(name), (unsigned char *)strZ(value)); + xmlSetProp(this->node, (const unsigned char *)strZ(name), (const unsigned char *)strZ(value)); FUNCTION_TEST_RETURN_VOID(); } @@ -97,13 +98,14 @@ xmlNodeChildAdd(XmlNode *const this, const XmlNode *const child) if (currentNode->node->type == XML_ELEMENT_NODE) { - XmlNode *const node = xmlNodeAdd(this, STR((char *)currentNode->node->name)); + XmlNode *const node = xmlNodeAdd(this, STR((const char *)currentNode->node->name)); // Copy node attributes for (xmlAttrPtr currentAttr = currentNode->node->properties; currentAttr != NULL; currentAttr = currentAttr->next) { xmlNodeAttributeSet( - node, STR((char *)currentAttr->name), xmlNodeAttribute(currentNode, STR((char *)currentAttr->name))); + node, STR((const char *)currentAttr->name), + xmlNodeAttribute(currentNode, STR((const char *)currentAttr->name))); } // Recurse to copy child nodes @@ -113,7 +115,7 @@ xmlNodeChildAdd(XmlNode *const this, const XmlNode *const child) { CHECK_FMT( AssertError, currentNode->node->type == XML_TEXT_NODE, "unknown type %u in node '%s'", currentNode->node->type, - (char *)currentNode->node->name); + currentNode->node->name); xmlNodeContentSet(this, xmlNodeContent(currentNode)); } diff --git a/src/build/config/render.c b/src/build/config/render.c index 8fbd24bfa..17545bd8a 100644 --- a/src/build/config/render.c +++ b/src/build/config/render.c @@ -564,19 +564,20 @@ bldCfgRenderValueAdd(const String *optType, const bool literal, const String *co FN_EXTERN int bldCfgRenderComparatorInt(const void *const int64Ptr1, const void *const int64Ptr2) { - return LST_COMPARATOR_CMP(cvtZToInt64(strZ(*(const String **)int64Ptr1)), cvtZToInt64(strZ(*(const String **)int64Ptr2))); + return LST_COMPARATOR_CMP( + cvtZToInt64(strZ(*(const String *const *)int64Ptr1)), cvtZToInt64(strZ(*(const String *const *)int64Ptr2))); } FN_EXTERN int bldCfgRenderComparatorSize(const void *const sizePtr1, const void *const sizePtr2) { - return LST_COMPARATOR_CMP(cfgParseSize(*(const String **)sizePtr1), cfgParseSize(*(const String **)sizePtr2)); + return LST_COMPARATOR_CMP(cfgParseSize(*(const String *const *)sizePtr1), cfgParseSize(*(const String *const *)sizePtr2)); } FN_EXTERN int bldCfgRenderComparatorTime(const void *const timePtr1, const void *const timePtr2) { - return LST_COMPARATOR_CMP(cfgParseTime(*(const String **)timePtr1), cfgParseTime(*(const String **)timePtr2)); + return LST_COMPARATOR_CMP(cfgParseTime(*(const String *const *)timePtr1), cfgParseTime(*(const String *const *)timePtr2)); } static String * diff --git a/src/build/help/render.c b/src/build/help/render.c index 0c95e8fa1..8bd4cedc3 100644 --- a/src/build/help/render.c +++ b/src/build/help/render.c @@ -46,7 +46,7 @@ bldHlpRenderXmlNode(const xmlNodePtr xml) for (xmlNodePtr currentNode = xml->children; currentNode != NULL; currentNode = currentNode->next) { - const String *const name = STR((char *)currentNode->name); + const String *const name = STR((const char *)currentNode->name); if (currentNode->type == XML_ELEMENT_NODE) { diff --git a/src/command/archive/common.c b/src/command/archive/common.c index 39b42d91f..0ed1e5846 100644 --- a/src/command/archive/common.c +++ b/src/command/archive/common.c @@ -264,10 +264,14 @@ archiveAsyncExec(const ArchiveMode archiveMode, const StringList *const commandE for (int fd = 3; fd < 1024; fd++) close(fd); - // Execute the binary. This statement will not return if it is successful. + // Execute the binary. This statement will not return if it is successful. execvp() requires non-const parameters because it + // modifies them after the fork. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" THROW_ON_SYS_ERROR_FMT( - execvp(strZ(strLstGet(commandExec, 0)), (char **const)strLstPtr(commandExec)) == -1, ExecuteError, + execvp(strZ(strLstGet(commandExec, 0)), UNCONSTIFY(char **, strLstPtr(commandExec))) == -1, ExecuteError, "unable to execute asynchronous '%s'", archiveMode == archiveModeGet ? CFGCMD_ARCHIVE_GET : CFGCMD_ARCHIVE_PUSH); +#pragma GCC diagnostic pop } #ifdef DEBUG_EXEC_TIME @@ -297,11 +301,11 @@ archiveAsyncExec(const ArchiveMode archiveMode, const StringList *const commandE FN_EXTERN int archiveIdComparator(const void *const archiveId1, const void *const archiveId2) { - ASSERT(strstr(strZ(*(String **)archiveId1), "-") != NULL); - ASSERT(strstr(strZ(*(String **)archiveId2), "-") != NULL); + ASSERT(strstr(strZ(*(const String *const *)archiveId1), "-") != NULL); + ASSERT(strstr(strZ(*(const String *const *)archiveId2), "-") != NULL); - const int id1 = cvtZToInt(strstr(strZ(*(String **)archiveId1), "-") + 1); - const int id2 = cvtZToInt(strstr(strZ(*(String **)archiveId2), "-") + 1); + const int id1 = cvtZToInt(strstr(strZ(*(const String *const *)archiveId1), "-") + 1); + const int id2 = cvtZToInt(strstr(strZ(*(const String *const *)archiveId2), "-") + 1); return LST_COMPARATOR_CMP(id1, id2); } diff --git a/src/command/backup/backup.c b/src/command/backup/backup.c index 3a9abf697..261a73eb5 100644 --- a/src/command/backup/backup.c +++ b/src/command/backup/backup.c @@ -1746,8 +1746,8 @@ backupProcessQueueComparator(const void *const item1, const void *const item2) ASSERT(item2 != NULL); // Unpack files - const ManifestFile file1 = manifestFileUnpack(backupProcessQueueComparatorManifest, *(const ManifestFilePack **)item1); - const ManifestFile file2 = manifestFileUnpack(backupProcessQueueComparatorManifest, *(const ManifestFilePack **)item2); + const ManifestFile file1 = manifestFileUnpack(backupProcessQueueComparatorManifest, *(const ManifestFilePack *const *)item1); + const ManifestFile file2 = manifestFileUnpack(backupProcessQueueComparatorManifest, *(const ManifestFilePack *const *)item2); // If the size differs then that's enough to determine order if (!backupProcessQueueComparatorBundle || file1.size > backupProcessQueueComparatorBundleLimit || diff --git a/src/command/backup/blockMap.c b/src/command/backup/blockMap.c index 4a5fd737d..43ff82d31 100644 --- a/src/command/backup/blockMap.c +++ b/src/command/backup/blockMap.c @@ -76,8 +76,8 @@ lstComparatorBlockMapReference(const void *const blockMapRef1, const void *const ASSERT(blockMapRef1 != NULL); ASSERT(blockMapRef2 != NULL); - const unsigned int reference1 = ((BlockMapReference *)blockMapRef1)->reference; - const unsigned int reference2 = ((BlockMapReference *)blockMapRef2)->reference; + const unsigned int reference1 = ((const BlockMapReference *)blockMapRef1)->reference; + const unsigned int reference2 = ((const BlockMapReference *)blockMapRef2)->reference; FUNCTION_TEST_RETURN(INT, LST_COMPARATOR_CMP(reference1, reference2)); } diff --git a/src/command/backup/blockMap.h b/src/command/backup/blockMap.h index 445c339d5..f4fbca027 100644 --- a/src/command/backup/blockMap.h +++ b/src/command/backup/blockMap.h @@ -62,14 +62,14 @@ Getters/Setters FN_INLINE_ALWAYS BlockMapItem * blockMapGet(const BlockMap *const this, const unsigned int mapIdx) { - return (BlockMapItem *)lstGet((List *const)this, mapIdx); + return (BlockMapItem *)lstGet((const List *const)this, mapIdx); } // Block map size FN_INLINE_ALWAYS unsigned int blockMapSize(const BlockMap *const this) { - return lstSize((List *const)this); + return lstSize((const List *const)this); } /*********************************************************************************************************************************** diff --git a/src/command/backup/pageChecksum.c b/src/command/backup/pageChecksum.c index f0cec587b..18502f9fb 100644 --- a/src/command/backup/pageChecksum.c +++ b/src/command/backup/pageChecksum.c @@ -109,7 +109,7 @@ pageChecksumProcess(THIS_VOID, const Buffer *const input) // Check that the entire page is zero for (unsigned int pageIdx = 0; pageIdx < this->pageSize / sizeof(size_t); pageIdx++) { - if (((size_t *)pageHeader)[pageIdx] != 0) + if (((const size_t *)pageHeader)[pageIdx] != 0) { pageValid = false; break; diff --git a/src/command/restore/restore.c b/src/command/restore/restore.c index 4a533e2e8..b1004f689 100644 --- a/src/command/restore/restore.c +++ b/src/command/restore/restore.c @@ -686,8 +686,8 @@ restoreManifestOwner(const Manifest *const manifest, const String **const rootRe StringList *const groupList = strLstNew(); RESTORE_MANIFEST_OWNER_GET(File, ); - RESTORE_MANIFEST_OWNER_GET(Link, *(ManifestLink *)); - RESTORE_MANIFEST_OWNER_GET(Path, *(ManifestPath *)); + RESTORE_MANIFEST_OWNER_GET(Link, *(const ManifestLink *)); + RESTORE_MANIFEST_OWNER_GET(Path, *(const ManifestPath *)); // Update users and groups in the manifest (this can only be done as root) // ------------------------------------------------------------------------------------------------------------------------- @@ -1855,8 +1855,8 @@ restoreProcessQueueComparator(const void *const item1, const void *const item2) ASSERT(item2 != NULL); // Unpack files - const ManifestFile file1 = manifestFileUnpack(restoreProcessQueueComparatorManifest, *(const ManifestFilePack **)item1); - const ManifestFile file2 = manifestFileUnpack(restoreProcessQueueComparatorManifest, *(const ManifestFilePack **)item2); + const ManifestFile file1 = manifestFileUnpack(restoreProcessQueueComparatorManifest, *(const ManifestFilePack *const *)item1); + const ManifestFile file2 = manifestFileUnpack(restoreProcessQueueComparatorManifest, *(const ManifestFilePack *const *)item2); // Zero length files should be ordered at the end if (file1.size == 0) diff --git a/src/common/compress/bz2/compress.c b/src/common/compress/bz2/compress.c index 17c6ee876..ddf1a053b 100644 --- a/src/common/compress/bz2/compress.c +++ b/src/common/compress/bz2/compress.c @@ -97,7 +97,10 @@ bz2CompressProcess(THIS_VOID, const Buffer *const uncompressed, Buffer *const co this->stream.avail_in = (unsigned int)bufUsed(uncompressed); // bzip2 does not accept const input buffers +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" this->stream.next_in = (char *)UNCONSTIFY(unsigned char *, bufPtrConst(uncompressed)); +#pragma GCC diagnostic pop } } diff --git a/src/common/compress/bz2/decompress.c b/src/common/compress/bz2/decompress.c index e53e1ab2f..720e5a6e2 100644 --- a/src/common/compress/bz2/decompress.c +++ b/src/common/compress/bz2/decompress.c @@ -88,7 +88,10 @@ bz2DecompressProcess(THIS_VOID, const Buffer *const compressed, Buffer *const un this->stream.avail_in = (unsigned int)bufUsed(compressed); // bzip2 does not accept const input buffers +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" this->stream.next_in = (char *)UNCONSTIFY(unsigned char *, bufPtrConst(compressed)); +#pragma GCC diagnostic pop } this->stream.avail_out = (unsigned int)bufRemains(uncompressed); diff --git a/src/common/crypto/md5.vendor.c.inc b/src/common/crypto/md5.vendor.c.inc index b59222025..fca6c216a 100644 --- a/src/common/crypto/md5.vendor.c.inc +++ b/src/common/crypto/md5.vendor.c.inc @@ -87,7 +87,7 @@ typedef struct { */ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) #define SET(n) \ - (*(MD5_u32plus *)&ptr[(n) * 4]) + (*(const MD5_u32plus *)&ptr[(n) * 4]) #define GET(n) \ SET(n) #else diff --git a/src/common/exec.c b/src/common/exec.c index c754265cc..2b7a09b60 100644 --- a/src/common/exec.c +++ b/src/common/exec.c @@ -155,7 +155,7 @@ then the original error should be rethrown. ***********************************************************************************************************************************/ // Helper to throw status error static void -execCheckStatusError(Exec *const this, const int status, const String *const output) +execCheckStatusError(Exec *const this, int status, const String *const output) { FUNCTION_TEST_BEGIN(); FUNCTION_LOG_PARAM(EXEC, this); @@ -173,7 +173,7 @@ execCheckStatusError(Exec *const this, const int status, const String *const out // Helper to throw signal error static void -execCheckSignalError(Exec *const this, const int status) +execCheckSignalError(Exec *const this, int status) { THROW_FMT(ExecuteError, "%s terminated unexpectedly on signal %d", strZ(this->name), WTERMSIG(status)); } @@ -353,8 +353,12 @@ execOpen(Exec *const this) // Assign stderr to the input side of the error pipe PIPE_DUP2(pipeError, 1, STDERR_FILENO); - // Execute the binary. This statement will not return if it is successful - execvp(strZ(execCommand(this)), (char **const)strLstPtr(this->param)); + // Execute the binary. This statement will not return if it is successful. execvp() requires non-const parameters because it + // modifies them after the fork. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + execvp(strZ(execCommand(this)), UNCONSTIFY(char **, strLstPtr(this->param))); +#pragma GCC diagnostic pop // If we got here then there was an error. We can't use a throw as we normally would because we have already shutdown // logging and we don't want to execute exit paths that might free parent resources which we still have references to. diff --git a/src/common/io/filter/group.c b/src/common/io/filter/group.c index fefee8eff..ae4cf1ff5 100644 --- a/src/common/io/filter/group.c +++ b/src/common/io/filter/group.c @@ -20,7 +20,7 @@ Contains the filter object and inout/output buffers. ***********************************************************************************************************************************/ typedef struct IoFilterData { - const Buffer **input; // Input buffer for filter + const Buffer *const *input; // Input buffer for filter Buffer *inputLocal; // Non-null if a locally created buffer that can be cleared IoFilter *filter; // Filter to apply Buffer *output; // Output buffer for filter @@ -200,7 +200,7 @@ ioFilterGroupOpen(IoFilterGroup *const this) // This cast is required because the compiler can't guarantee the const-ness of this object, i.e. it could be // modified in other parts of the code. This is actually expected and the only reason we need this const is to match // the const-ness of the input buffer provided by the caller. - filterData->input = (const Buffer **)lastOutputBuffer; + filterData->input = (const Buffer *const *)lastOutputBuffer; filterData->inputLocal = *lastOutputBuffer; } diff --git a/src/common/io/http/request.c b/src/common/io/http/request.c index d3b8d0155..1c9d32e8b 100644 --- a/src/common/io/http/request.c +++ b/src/common/io/http/request.c @@ -413,7 +413,7 @@ httpRequestMultiAdd( THROW(AssertError, "unable to construct unique boundary"); bufCatC( - this->boundaryRaw, (unsigned char *)HTTP_MULTIPART_BOUNDARY_EXTRA, + this->boundaryRaw, (const unsigned char *)HTTP_MULTIPART_BOUNDARY_EXTRA, bufUsed(this->boundaryRaw) - HTTP_MULTIPART_BOUNDARY_INIT_SIZE, HTTP_MULTIPART_BOUNDARY_NEXT); } diff --git a/src/common/io/tls/client.c b/src/common/io/tls/client.c index 7f991bfd7..b81aeb41e 100644 --- a/src/common/io/tls/client.c +++ b/src/common/io/tls/client.c @@ -320,8 +320,12 @@ tlsClientOpen(THIS_VOID) tlsSession = SSL_new(this->context); cryptoError(tlsSession == NULL, "unable to create TLS session"); - // Set server host name used for validation + // Set server host name used for validation. The exception here is necessary for MacOS which for some reason defines the + // host name parameter as void * rather than const char * as on most platforms. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" cryptoError(SSL_set_tlsext_host_name(tlsSession, strZ(this->host)) != 1, "unable to set TLS host name"); +#pragma GCC diagnostic pop // Open TLS session TRY_BEGIN() diff --git a/src/common/memContext.c b/src/common/memContext.c index beba3d6e4..4b5bf5147 100644 --- a/src/common/memContext.c +++ b/src/common/memContext.c @@ -868,7 +868,7 @@ memNewPtrArray(const size_t size) /**********************************************************************************************************************************/ FN_EXTERN void * -memResize(const void *const buffer, const size_t size) +memResize(void *const buffer, const size_t size) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM_P(VOID, buffer); @@ -1127,7 +1127,7 @@ memContextSize(const MemContext *const this) // Size of struct and extra size_t total = 0; - const unsigned char *offset = (unsigned char *)(this + 1) + this->allocExtra; + const unsigned char *offset = (const unsigned char *)(this + 1) + this->allocExtra; // Size of child contexts if (this->childQty == memQtyOne) @@ -1195,7 +1195,7 @@ memContextSize(const MemContext *const this) if (this->callbackQty != memQtyNone) offset += sizeof(MemContextCallbackOne); - FUNCTION_TEST_RETURN(SIZE, (size_t)(offset - (unsigned char *)this) + total); + FUNCTION_TEST_RETURN(SIZE, (size_t)(offset - (const unsigned char *)this) + total); } #endif // DEBUG diff --git a/src/common/memContext.h b/src/common/memContext.h index f5ebc8c30..5b80b00aa 100644 --- a/src/common/memContext.h +++ b/src/common/memContext.h @@ -79,7 +79,7 @@ FN_EXTERN void *memNew(size_t size); FN_EXTERN void *memNewPtrArray(size_t size); // Reallocate to the new size. Original buffer pointer is undefined on return. -FN_EXTERN void *memResize(const void *buffer, size_t size); +FN_EXTERN void *memResize(void *buffer, size_t size); // Free memory allocation FN_EXTERN void memFree(void *buffer); diff --git a/src/common/type/list.c b/src/common/type/list.c index e627989ce..8f7743de7 100644 --- a/src/common/type/list.c +++ b/src/common/type/list.c @@ -84,7 +84,7 @@ lstComparatorStr(const void *const item1, const void *const item2) ASSERT(item1 != NULL); ASSERT(item2 != NULL); - FUNCTION_TEST_RETURN(INT, strCmp(*(String **)item1, *(String **)item2)); + FUNCTION_TEST_RETURN(INT, strCmp(*(const String *const *)item1, *(const String *const *)item2)); } /**********************************************************************************************************************************/ @@ -99,8 +99,8 @@ lstComparatorInt(const void *const intPtr1, const void *const intPtr2) ASSERT(intPtr1 != NULL); ASSERT(intPtr2 != NULL); - const int int1 = *(int *)intPtr1; - const int int2 = *(int *)intPtr2; + const int int1 = *(const int *)intPtr1; + const int int2 = *(const int *)intPtr2; FUNCTION_TEST_RETURN(INT, LST_COMPARATOR_CMP(int1, int2)); } @@ -117,8 +117,8 @@ lstComparatorUInt(const void *const uintPtr1, const void *const uintPtr2) ASSERT(uintPtr1 != NULL); ASSERT(uintPtr2 != NULL); - const unsigned int uint1 = *(unsigned int *)uintPtr1; - const unsigned int uint2 = *(unsigned int *)uintPtr2; + const unsigned int uint1 = *(const unsigned int *)uintPtr1; + const unsigned int uint2 = *(const unsigned int *)uintPtr2; FUNCTION_TEST_RETURN(INT, LST_COMPARATOR_CMP(uint1, uint2)); } @@ -135,7 +135,7 @@ lstComparatorZ(const void *const item1, const void *const item2) ASSERT(item1 != NULL); ASSERT(item2 != NULL); - FUNCTION_TEST_RETURN(INT, strcmp(*(char **)item1, *(char **)item2)); + FUNCTION_TEST_RETURN(INT, strcmp(*(const char *const *)item1, *(const char *const *)item2)); } /*********************************************************************************************************************************** @@ -237,8 +237,8 @@ lstFindIdx(const List *const this, const void *const item) FUNCTION_TEST_RETURN(UINT, result == NULL ? LIST_NOT_FOUND : lstIdx(this, result)); } -FN_EXTERN void * -lstFindDefault(const List *const this, const void *const item, void *const itemDefault) +FN_EXTERN const void * +lstFindDefault(const List *const this, const void *const item, const void *const itemDefault) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(LIST, this); @@ -251,7 +251,7 @@ lstFindDefault(const List *const this, const void *const item, void *const itemD void *const result = lstFind(this, item); - FUNCTION_TEST_RETURN_P(VOID, result == NULL ? itemDefault : result); + FUNCTION_TEST_RETURN_CONST_P(VOID, result == NULL ? itemDefault : result); } /**********************************************************************************************************************************/ @@ -267,9 +267,9 @@ lstIdx(const List *const this, const void *const item) ASSERT(item != NULL); // Item pointers should always be aligned with the beginning of an item in the list - ASSERT((size_t)((unsigned char *const)item - this->list) % this->itemSize == 0); + ASSERT((size_t)((const unsigned char *const)item - this->list) % this->itemSize == 0); - const size_t result = (size_t)((unsigned char *const)item - this->list) / this->itemSize; + const size_t result = (size_t)((const unsigned char *const)item - this->list) / this->itemSize; // Item pointers should always be in range ASSERT(result < lstSize(this)); diff --git a/src/common/type/list.h b/src/common/type/list.h index 0f18c9544..b34cc5c5a 100644 --- a/src/common/type/list.h +++ b/src/common/type/list.h @@ -118,7 +118,7 @@ FN_EXTERN void *lstGetLast(const List *this); // Find an item in the list FN_EXTERN void *lstFind(const List *this, const void *item); -FN_EXTERN void *lstFindDefault(const List *this, const void *item, void *itemDefault); +FN_EXTERN const void *lstFindDefault(const List *this, const void *item, const void *itemDefault); FN_EXTERN unsigned int lstFindIdx(const List *this, const void *item); // Does an item exist in the list? diff --git a/src/common/type/object.h b/src/common/type/object.h index 09d2993f1..2e54bf29e 100644 --- a/src/common/type/object.h +++ b/src/common/type/object.h @@ -84,7 +84,7 @@ lstSize(const List *const this) The macro also ensures that this != NULL so there is no need to do that in the calling function. ***********************************************************************************************************************************/ -#define THIS_PUB(type) ((type##Pub *)thisNotNull(this)) +#define THIS_PUB(type) ((const type##Pub *)thisNotNull(this)) FN_INLINE_ALWAYS const void * thisNotNull(const void *const this) diff --git a/src/common/type/pack.c b/src/common/type/pack.c index 87b3fca93..f693e5ba0 100644 --- a/src/common/type/pack.c +++ b/src/common/type/pack.c @@ -1104,7 +1104,7 @@ pckReadStr(PackRead *const this, PckReadStrParam param) while (strSize(result) != sizeExpected) { const size_t sizeRead = pckReadBuffer(this, sizeExpected - strSize(result)); - strCatZN(result, (char *)this->bufferPtr + this->bufferPos, sizeRead); + strCatZN(result, (const char *)this->bufferPtr + this->bufferPos, sizeRead); this->bufferPos += sizeRead; } } @@ -1746,8 +1746,8 @@ pckWritePack(PackWrite *const this, const Pack *const value, const PckWritePackP ASSERT(value != NULL); pckWriteTag(this, pckTypeMapPack, param.id, 0); - pckWriteU64Internal(this, bufUsed((Buffer *)value)); - pckWriteBuffer(this, (Buffer *)value); + pckWriteU64Internal(this, bufUsed((const Buffer *)value)); + pckWriteBuffer(this, (const Buffer *)value); } FUNCTION_TEST_RETURN(PACK_WRITE, this); diff --git a/src/common/type/string.c b/src/common/type/string.c index f7c80e87e..3610bbaaf 100644 --- a/src/common/type/string.c +++ b/src/common/type/string.c @@ -478,7 +478,7 @@ strCatBuf(String *const this, const Buffer *const buffer) ASSERT(this != NULL); ASSERT(buffer != NULL); - FUNCTION_TEST_RETURN(STRING, strCatZN(this, (char *)bufPtrConst(buffer), bufUsed(buffer))); + FUNCTION_TEST_RETURN(STRING, strCatZN(this, (const char *)bufPtrConst(buffer), bufUsed(buffer))); } /**********************************************************************************************************************************/ diff --git a/src/common/type/stringList.c b/src/common/type/stringList.c index 85302c8b5..553199430 100644 --- a/src/common/type/stringList.c +++ b/src/common/type/stringList.c @@ -287,7 +287,7 @@ strLstFindIdx(const StringList *const this, const String *const string, const St ASSERT(this != NULL); ASSERT(string != NULL); - const unsigned int result = lstFindIdx((List *)this, &string); + const unsigned int result = lstFindIdx((const List *)this, &string); if (result == LIST_NOT_FOUND && param.required) THROW_FMT(AssertError, "unable to find '%s' in string list", strZ(string)); diff --git a/src/common/type/stringList.h b/src/common/type/stringList.h index 209c7eb18..9be976189 100644 --- a/src/common/type/stringList.h +++ b/src/common/type/stringList.h @@ -53,7 +53,7 @@ strLstComparatorSet(StringList *const this, ListComparator *const comparator) FN_INLINE_ALWAYS unsigned int strLstSize(const StringList *const this) { - return lstSize((List *)this); + return lstSize((const List *)this); } // Is the list empty? @@ -92,7 +92,7 @@ FN_EXTERN String *strLstAddIfMissing(StringList *this, const String *string); FN_INLINE_ALWAYS bool strLstExists(const StringList *const this, const String *const string) { - return lstExists((List *)this, &string); + return lstExists((const List *)this, &string); } // Find string index in the list @@ -114,7 +114,7 @@ FN_EXTERN String *strLstInsert(StringList *this, unsigned int listIdx, const Str FN_INLINE_ALWAYS String * strLstGet(const StringList *const this, const unsigned int listIdx) { - return *(String **)lstGet((List *)this, listIdx); + return *(String **)lstGet((const List *)this, listIdx); } // Join a list of strings into a single string using the specified separator and quote with specified quote character diff --git a/src/common/type/variant.c b/src/common/type/variant.c index 61247cdeb..0e6b2cd47 100644 --- a/src/common/type/variant.c +++ b/src/common/type/variant.c @@ -233,7 +233,7 @@ varBool(const Variant *const this) ASSERT(this != NULL); ASSERT(varType(this) == varTypeBool); - FUNCTION_TEST_RETURN(BOOL, ((VariantBool *)this)->pub.data); + FUNCTION_TEST_RETURN(BOOL, ((const VariantBool *)this)->pub.data); } FN_EXTERN bool @@ -339,7 +339,7 @@ varInt(const Variant *const this) ASSERT(this != NULL); ASSERT(varType(this) == varTypeInt); - FUNCTION_TEST_RETURN(INT, ((VariantInt *)this)->pub.data); + FUNCTION_TEST_RETURN(INT, ((const VariantInt *)this)->pub.data); } FN_EXTERN int @@ -452,7 +452,7 @@ varInt64(const Variant *const this) ASSERT(this != NULL); ASSERT(varType(this) == varTypeInt64); - FUNCTION_TEST_RETURN(INT64, ((VariantInt64 *)this)->pub.data); + FUNCTION_TEST_RETURN(INT64, ((const VariantInt64 *)this)->pub.data); } FN_EXTERN int64_t @@ -549,7 +549,7 @@ varUInt(const Variant *const this) ASSERT(this != NULL); ASSERT(varType(this) == varTypeUInt); - FUNCTION_TEST_RETURN(UINT, ((VariantUInt *)this)->pub.data); + FUNCTION_TEST_RETURN(UINT, ((const VariantUInt *)this)->pub.data); } FN_EXTERN unsigned int @@ -671,7 +671,7 @@ varUInt64(const Variant *const this) ASSERT(this != NULL); ASSERT(varType(this) == varTypeUInt64); - FUNCTION_TEST_RETURN(UINT64, ((VariantUInt64 *)this)->pub.data); + FUNCTION_TEST_RETURN(UINT64, ((const VariantUInt64 *)this)->pub.data); } FN_EXTERN uint64_t @@ -781,7 +781,7 @@ varKv(const Variant *const this) if (this != NULL) { ASSERT(varType(this) == varTypeKeyValue); - result = ((VariantKeyValue *)this)->data; + result = ((const VariantKeyValue *)this)->data; } FUNCTION_TEST_RETURN(KEY_VALUE, result); @@ -874,7 +874,7 @@ varStr(const Variant *const this) if (this != NULL) { ASSERT(varType(this) == varTypeString); - result = ((VariantString *)this)->pub.data; + result = ((const VariantString *)this)->pub.data; } FUNCTION_TEST_RETURN(STRING, result); @@ -981,7 +981,7 @@ varVarLst(const Variant *const this) if (this != NULL) { ASSERT(varType(this) == varTypeVariantList); - result = ((VariantVariantList *)this)->data; + result = ((const VariantVariantList *)this)->data; } FUNCTION_TEST_RETURN(VARIANT_LIST, result); diff --git a/src/common/type/variantList.h b/src/common/type/variantList.h index 1b891a1d0..b0bd30dfd 100644 --- a/src/common/type/variantList.h +++ b/src/common/type/variantList.h @@ -35,7 +35,7 @@ Getters/Setters FN_INLINE_ALWAYS unsigned int varLstSize(const VariantList *const this) { - return lstSize((List *)this); + return lstSize((const List *)this); } // Is the list empty? @@ -60,7 +60,7 @@ varLstAdd(VariantList *const this, Variant *const data) FN_INLINE_ALWAYS Variant * varLstGet(const VariantList *const this, const unsigned int listIdx) { - return *(Variant **)lstGet((List *)this, listIdx); + return *(Variant **)lstGet((const List *)this, listIdx); } // Move to new parent mem context diff --git a/src/common/type/xml.c b/src/common/type/xml.c index 2b6127d48..1b87cacec 100644 --- a/src/common/type/xml.c +++ b/src/common/type/xml.c @@ -116,7 +116,7 @@ xmlNodeAdd(XmlNode *const this, const String *const name) ASSERT(this != NULL); ASSERT(name != NULL); - XmlNode *const result = xmlNodeNew(xmlNewNode(NULL, BAD_CAST strZ(name))); + XmlNode *const result = xmlNodeNew(xmlNewNode(NULL, (const xmlChar *)strZ(name))); xmlAddChild(this->node, result->node); FUNCTION_TEST_RETURN(XML_NODE, result); @@ -177,7 +177,7 @@ xmlNodeContentSet(XmlNode *const this, const String *const content) ASSERT(this != NULL); ASSERT(content != NULL); - xmlAddChild(this->node, xmlNewText(BAD_CAST strZ(content))); + xmlAddChild(this->node, xmlNewText((const xmlChar *)strZ(content))); FUNCTION_TEST_RETURN_VOID(); } @@ -192,7 +192,7 @@ xmlNodeName(const XmlNode *const this) ASSERT(this != NULL); - FUNCTION_TEST_RETURN(STRING, strNewZ((char *)this->node->name)); + FUNCTION_TEST_RETURN(STRING, strNewZ((const char *)this->node->name)); } /**********************************************************************************************************************************/ @@ -211,7 +211,7 @@ xmlNodeChildList(const XmlNode *const this, const String *const name) for (xmlNodePtr currentNode = this->node->children; currentNode != NULL; currentNode = currentNode->next) { - if (currentNode->type == XML_ELEMENT_NODE && strEqZ(name, (char *)currentNode->name)) + if (currentNode->type == XML_ELEMENT_NODE && strEqZ(name, (const char *)currentNode->name)) xmlNodeLstAdd(list, currentNode); } @@ -234,7 +234,7 @@ xmlNodeChildListMulti(const XmlNode *const this, const StringList *const nameLis for (xmlNodePtr currentNode = this->node->children; currentNode != NULL; currentNode = currentNode->next) { - if (currentNode->type == XML_ELEMENT_NODE && strLstExists(nameList, STR((char *)currentNode->name))) + if (currentNode->type == XML_ELEMENT_NODE && strLstExists(nameList, STR((const char *)currentNode->name))) xmlNodeLstAdd(list, currentNode); } @@ -259,7 +259,7 @@ xmlNodeChildN(const XmlNode *const this, const String *const name, const unsigne for (xmlNodePtr currentNode = this->node->children; currentNode != NULL; currentNode = currentNode->next) { - if (currentNode->type == XML_ELEMENT_NODE && strEqZ(name, (char *)currentNode->name)) + if (currentNode->type == XML_ELEMENT_NODE && strEqZ(name, (const char *)currentNode->name)) { if (childIdx == index) { @@ -312,13 +312,13 @@ xmlDocumentNew(const String *const rootName) { *this = (XmlDocument) { - .xml = xmlNewDoc(BAD_CAST "1.0"), + .xml = xmlNewDoc((const xmlChar *)"1.0"), }; // Set callback to ensure xml document is freed memContextCallbackSet(objMemContext(this), xmlDocumentFreeResource, this); - this->pub.root = xmlNodeNew(xmlNewNode(NULL, BAD_CAST strZ(rootName))); + this->pub.root = xmlNodeNew(xmlNewNode(NULL, (const xmlChar *)strZ(rootName))); xmlDocSetRootElement(this->xml, xmlDocumentRoot(this)->node); } OBJ_NEW_END(); diff --git a/src/common/type/xml.h b/src/common/type/xml.h index 796c911eb..5587ffc31 100644 --- a/src/common/type/xml.h +++ b/src/common/type/xml.h @@ -44,7 +44,7 @@ FN_EXTERN Buffer *xmlDocumentBuf(const XmlDocument *this); FN_INLINE_ALWAYS XmlNode * xmlDocumentRoot(const XmlDocument *const this) { - return ((XmlDocumentPub *const)this)->root; + return ((const XmlDocumentPub *const)this)->root; } /*********************************************************************************************************************************** @@ -94,14 +94,14 @@ Node List Getters FN_INLINE_ALWAYS XmlNode * xmlNodeLstGet(const XmlNodeList *const this, const unsigned int listIdx) { - return *(XmlNode **)lstGet((List *const)this, listIdx); + return *(XmlNode **)lstGet((const List *const)this, listIdx); } // Node list size FN_INLINE_ALWAYS unsigned int xmlNodeLstSize(const XmlNodeList *const this) { - return lstSize((List *const)this); + return lstSize((const List *const)this); } /*********************************************************************************************************************************** diff --git a/src/info/manifest.c b/src/info/manifest.c index fdbae0ebd..a622bf6c6 100644 --- a/src/info/manifest.c +++ b/src/info/manifest.c @@ -264,7 +264,7 @@ manifestFilePack(const Manifest *const manifest, const ManifestFile *const file) *(StringPub *)result = (StringPub){.size = (unsigned int)strSize(file->name), .buffer = (char *)result + sizeof(StringPub)}; size_t resultPos = sizeof(StringPub); - memcpy(result + resultPos, (uint8_t *)strZ(file->name), nameSize); + memcpy(result + resultPos, (const uint8_t *)strZ(file->name), nameSize); resultPos += nameSize; // Copy pack data @@ -282,7 +282,7 @@ manifestFilePack(const Manifest *const manifest, const ManifestFile *const file) }; resultPos += sizeof(StringPub); - memcpy(result + resultPos, (uint8_t *)strZ(file->checksumPageErrorList), strSize(file->checksumPageErrorList) + 1); + memcpy(result + resultPos, (const uint8_t *)strZ(file->checksumPageErrorList), strSize(file->checksumPageErrorList) + 1); } FUNCTION_TEST_RETURN_TYPE_P(ManifestFilePack, (ManifestFilePack *)result); @@ -3099,7 +3099,7 @@ manifestFileUpdate(Manifest *const this, const ManifestFile *const file) /*********************************************************************************************************************************** Link functions and getters/setters ***********************************************************************************************************************************/ -FN_EXTERN const ManifestLink * +FN_EXTERN ManifestLink * manifestLinkFind(const Manifest *const this, const String *const name) { FUNCTION_TEST_BEGIN(); @@ -3110,12 +3110,12 @@ manifestLinkFind(const Manifest *const this, const String *const name) ASSERT(this != NULL); ASSERT(name != NULL); - const ManifestLink *const result = lstFind(this->pub.linkList, &name); + ManifestLink *const result = lstFind(this->pub.linkList, &name); if (result == NULL) THROW_FMT(AssertError, "unable to find '%s' in manifest link list", strZ(name)); - FUNCTION_TEST_RETURN_CONST(MANIFEST_LINK, result); + FUNCTION_TEST_RETURN(MANIFEST_LINK, result); } FN_EXTERN void @@ -3148,7 +3148,7 @@ manifestLinkUpdate(const Manifest *const this, const String *const name, const S ASSERT(name != NULL); ASSERT(destination != NULL); - ManifestLink *const link = (ManifestLink *)manifestLinkFind(this, name); + ManifestLink *const link = (ManifestLink *const)manifestLinkFind(this, name); MEM_CONTEXT_BEGIN(lstMemContext(this->pub.linkList)) { @@ -3212,7 +3212,7 @@ manifestPathPg(const String *const manifestPath) /*********************************************************************************************************************************** Target functions and getters/setters ***********************************************************************************************************************************/ -FN_EXTERN const ManifestTarget * +FN_EXTERN ManifestTarget * manifestTargetFind(const Manifest *const this, const String *const name) { FUNCTION_TEST_BEGIN(); @@ -3223,12 +3223,12 @@ manifestTargetFind(const Manifest *const this, const String *const name) ASSERT(this != NULL); ASSERT(name != NULL); - const ManifestTarget *const result = lstFind(this->pub.targetList, &name); + ManifestTarget *const result = lstFind(this->pub.targetList, &name); if (result == NULL) THROW_FMT(AssertError, "unable to find '%s' in manifest target list", strZ(name)); - FUNCTION_TEST_RETURN_CONST(MANIFEST_TARGET, result); + FUNCTION_TEST_RETURN(MANIFEST_TARGET, result); } FN_EXTERN String * diff --git a/src/info/manifest.h b/src/info/manifest.h index 0bf04148a..0562aeea0 100644 --- a/src/info/manifest.h +++ b/src/info/manifest.h @@ -318,7 +318,7 @@ FN_INLINE_ALWAYS const ManifestDb * manifestDbFindDefault(const Manifest *const this, const String *const name, const ManifestDb *const dbDefault) { ASSERT_INLINE(name != NULL); - return lstFindDefault(THIS_PUB(Manifest)->dbList, &name, (void *)dbDefault); + return lstFindDefault(THIS_PUB(Manifest)->dbList, &name, (const void *)dbDefault); } FN_INLINE_ALWAYS unsigned int @@ -399,14 +399,14 @@ manifestLink(const Manifest *const this, const unsigned int linkIdx) } FN_EXTERN void manifestLinkAdd(Manifest *this, const ManifestLink *link); -FN_EXTERN const ManifestLink *manifestLinkFind(const Manifest *this, const String *name); +FN_EXTERN ManifestLink *manifestLinkFind(const Manifest *this, const String *name); // If the link requested is not found in the list, return the default passed rather than throw an error FN_INLINE_ALWAYS const ManifestLink * manifestLinkFindDefault(const Manifest *const this, const String *const name, const ManifestLink *const linkDefault) { ASSERT_INLINE(name != NULL); - return lstFindDefault(THIS_PUB(Manifest)->linkList, &name, (void *)linkDefault); + return lstFindDefault(THIS_PUB(Manifest)->linkList, &name, (const void *)linkDefault); } FN_EXTERN void manifestLinkRemove(const Manifest *this, const String *name); @@ -435,7 +435,7 @@ FN_INLINE_ALWAYS const ManifestPath * manifestPathFindDefault(const Manifest *const this, const String *const name, const ManifestPath *const pathDefault) { ASSERT_INLINE(name != NULL); - return lstFindDefault(THIS_PUB(Manifest)->pathList, &name, (void *)pathDefault); + return lstFindDefault(THIS_PUB(Manifest)->pathList, &name, (const void *)pathDefault); } // Data directory relative path for any manifest file/link/path/target name @@ -457,14 +457,14 @@ manifestTarget(const Manifest *const this, const unsigned int targetIdx) } FN_EXTERN void manifestTargetAdd(Manifest *this, const ManifestTarget *target); -FN_EXTERN const ManifestTarget *manifestTargetFind(const Manifest *this, const String *name); +FN_EXTERN ManifestTarget *manifestTargetFind(const Manifest *this, const String *name); // If the target requested is not found in the list, return the default passed rather than throw an error FN_INLINE_ALWAYS const ManifestTarget * manifestTargetFindDefault(const Manifest *const this, const String *const name, const ManifestTarget *const targetDefault) { ASSERT_INLINE(name != NULL); - return lstFindDefault(THIS_PUB(Manifest)->targetList, &name, (void *)targetDefault); + return lstFindDefault(THIS_PUB(Manifest)->targetList, &name, (const void *)targetDefault); } // Base target, i.e. the target that is the data directory diff --git a/src/postgres/interface.c b/src/postgres/interface.c index b68f3484c..e40bbb8e1 100644 --- a/src/postgres/interface.c +++ b/src/postgres/interface.c @@ -208,7 +208,7 @@ pgControlCrcValidate(const Buffer *const controlFile, const PgInterface *const i { // Calculate CRC and retrieve expected CRC const uint32_t crcCalculated = crc32cOne(bufPtrConst(controlFile), result); - const uint32_t crcExpected = *((uint32_t *)(bufPtrConst(controlFile) + result)); + const uint32_t crcExpected = *((const uint32_t *)(bufPtrConst(controlFile) + result)); // If CRC does not match if (crcCalculated != crcExpected) diff --git a/src/postgres/interface/version.intern.h b/src/postgres/interface/version.intern.h index 5a31706b7..5ab69d453 100644 --- a/src/postgres/interface/version.intern.h +++ b/src/postgres/interface/version.intern.h @@ -27,9 +27,9 @@ alpha/beta/rc period without needing to be updated, unless of course the actual ASSERT(controlFile != NULL); \ \ return \ - ((ControlFileData *)controlFile)->pg_control_version == PG_CONTROL_VERSION && \ - ((ControlFileData *)controlFile)->catalog_version_no >= CATALOG_VERSION_NO && \ - ((ControlFileData *)controlFile)->catalog_version_no < (CATALOG_VERSION_NO / 100000 + 1) * 100000; \ + ((const ControlFileData *)controlFile)->pg_control_version == PG_CONTROL_VERSION && \ + ((const ControlFileData *)controlFile)->catalog_version_no >= CATALOG_VERSION_NO && \ + ((const ControlFileData *)controlFile)->catalog_version_no < (CATALOG_VERSION_NO / 100000 + 1) * 100000; \ } #else @@ -41,8 +41,8 @@ alpha/beta/rc period without needing to be updated, unless of course the actual ASSERT(controlFile != NULL); \ \ return \ - ((ControlFileData *)controlFile)->pg_control_version == PG_CONTROL_VERSION && \ - ((ControlFileData *)controlFile)->catalog_version_no == CATALOG_VERSION_NO; \ + ((const ControlFileData *)controlFile)->pg_control_version == PG_CONTROL_VERSION && \ + ((const ControlFileData *)controlFile)->catalog_version_no == CATALOG_VERSION_NO; \ } #endif @@ -64,13 +64,13 @@ Read the version specific pg_control into a general data structure \ return (PgControl) \ { \ - .systemId = ((ControlFileData *)controlFile)->system_identifier, \ - .catalogVersion = ((ControlFileData *)controlFile)->catalog_version_no, \ - .checkpoint = ((ControlFileData *)controlFile)->checkPoint, \ - .timeline = ((ControlFileData *)controlFile)->checkPointCopy.ThisTimeLineID, \ - .pageSize = ((ControlFileData *)controlFile)->blcksz, \ - .walSegmentSize = ((ControlFileData *)controlFile)->xlog_seg_size, \ - .pageChecksumVersion = ((ControlFileData *)controlFile)->data_checksum_version, \ + .systemId = ((const ControlFileData *)controlFile)->system_identifier, \ + .catalogVersion = ((const ControlFileData *)controlFile)->catalog_version_no, \ + .checkpoint = ((const ControlFileData *)controlFile)->checkPoint, \ + .timeline = ((const ControlFileData *)controlFile)->checkPointCopy.ThisTimeLineID, \ + .pageSize = ((const ControlFileData *)controlFile)->blcksz, \ + .walSegmentSize = ((const ControlFileData *)controlFile)->xlog_seg_size, \ + .pageChecksumVersion = ((const ControlFileData *)controlFile)->data_checksum_version, \ }; \ } @@ -137,7 +137,7 @@ Determine if the supplied WAL is for this version of PostgreSQL { \ ASSERT(walFile != NULL); \ \ - return ((XLogPageHeaderData *)walFile)->xlp_magic == XLOG_PAGE_MAGIC; \ + return ((const XLogPageHeaderData *)walFile)->xlp_magic == XLOG_PAGE_MAGIC; \ } #endif @@ -157,8 +157,8 @@ Read the version specific WAL header into a general data structure \ return (PgWal) \ { \ - .systemId = ((XLogLongPageHeaderData *)walFile)->xlp_sysid, \ - .size = ((XLogLongPageHeaderData *)walFile)->xlp_seg_size, \ + .systemId = ((const XLogLongPageHeaderData *)walFile)->xlp_sysid, \ + .size = ((const XLogLongPageHeaderData *)walFile)->xlp_seg_size, \ }; \ } diff --git a/src/storage/sftp/storage.c b/src/storage/sftp/storage.c index 3eadb97ff..14b2621fc 100644 --- a/src/storage/sftp/storage.c +++ b/src/storage/sftp/storage.c @@ -1310,7 +1310,7 @@ storageSftpNew( // requires twice as much space (hashSize * 2) as the raw version. char fingerprint[256]; - encodeToStr(encodingHex, (unsigned char *)binaryFingerprint, hashSize, fingerprint); + encodeToStr(encodingHex, (const unsigned char *)binaryFingerprint, hashSize, fingerprint); if (strcmp(fingerprint, strZ(param.hostFingerprint)) != 0) { diff --git a/test/src/common/harnessLibSsh2.c b/test/src/common/harnessLibSsh2.c index 6436a0ecb..901d48caf 100644 --- a/test/src/common/harnessLibSsh2.c +++ b/test/src/common/harnessLibSsh2.c @@ -383,7 +383,12 @@ libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_ if (hrnLibSsh2->errMsg != NULL) { - *errmsg = hrnLibSsh2->errMsg; + // Const error messages are used for testing but the function requires them to be returned non-const. This should be safe + // because the value is never modified by the calling function. If that changes, there will be a segfault during testing. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + *errmsg = UNCONSTIFY(char *, hrnLibSsh2->errMsg); +#pragma GCC diagnostic pop *errmsg_len = (int)(strlen(hrnLibSsh2->errMsg) + 1); } else diff --git a/test/src/common/harnessLibSsh2.h b/test/src/common/harnessLibSsh2.h index c17377eae..918aa8a0c 100644 --- a/test/src/common/harnessLibSsh2.h +++ b/test/src/common/harnessLibSsh2.h @@ -126,7 +126,7 @@ typedef struct HrnLibSsh2 TimeMSec sleep; // Sleep specified milliseconds before returning from function size_t len; // libssh2_session_hostkey len int type; // libssh2_session_hostkey type - char *errMsg; // libssh2_session_last_error error msg + const char *errMsg; // libssh2_session_last_error error msg } HrnLibSsh2; /*********************************************************************************************************************************** diff --git a/test/src/common/harnessPq.c b/test/src/common/harnessPq.c index 7ae7d29e5..30cf6678b 100644 --- a/test/src/common/harnessPq.c +++ b/test/src/common/harnessPq.c @@ -218,7 +218,7 @@ Shim for PQstatus() ConnStatusType PQstatus(const PGconn *conn) { - return (ConnStatusType)hrnPqScriptRun(HRN_PQ_STATUS, NULL, (HrnPqScript *)conn)->resultInt; + return (ConnStatusType)hrnPqScriptRun(HRN_PQ_STATUS, NULL, (const HrnPqScript *)conn)->resultInt; } /*********************************************************************************************************************************** @@ -227,7 +227,12 @@ Shim for PQerrorMessage() char * PQerrorMessage(const PGconn *conn) { - return (char *)hrnPqScriptRun(HRN_PQ_ERRORMESSAGE, NULL, (HrnPqScript *)conn)->resultZ; + // Const error messages are used for testing but the function requires them to be returned non-const. This should be safe + // because the value is never modified by the calling function. If that changes, there will be a segfault during testing. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + return UNCONSTIFY(char *, hrnPqScriptRun(HRN_PQ_ERRORMESSAGE, NULL, (const HrnPqScript *)conn)->resultZ); +#pragma GCC diagnostic pop } /*********************************************************************************************************************************** @@ -276,7 +281,7 @@ Shim for PQsocket() int PQsocket(const PGconn *conn) { - int result = hrnPqScriptRun(HRN_PQ_SOCKET, NULL, (HrnPqScript *)conn)->resultInt; + int result = hrnPqScriptRun(HRN_PQ_SOCKET, NULL, (const HrnPqScript *)conn)->resultInt; hrnFdReadyShimOne(result == true); @@ -340,7 +345,7 @@ Shim for PQresultStatus() ExecStatusType PQresultStatus(const PGresult *res) { - return (ExecStatusType)hrnPqScriptRun(HRN_PQ_RESULTSTATUS, NULL, (HrnPqScript *)res)->resultInt; + return (ExecStatusType)hrnPqScriptRun(HRN_PQ_RESULTSTATUS, NULL, (const HrnPqScript *)res)->resultInt; } /*********************************************************************************************************************************** @@ -349,7 +354,12 @@ Shim for PQresultErrorMessage() char * PQresultErrorMessage(const PGresult *res) { - return (char *)hrnPqScriptRun(HRN_PQ_RESULTERRORMESSAGE, NULL, (HrnPqScript *)res)->resultZ; + // Const error messages are used for testing but the function requires them to be returned non-const. This should be safe + // because the value is never modified by the calling function. If that changes, there will be a segfault during testing. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + return UNCONSTIFY(char *, hrnPqScriptRun(HRN_PQ_RESULTERRORMESSAGE, NULL, (const HrnPqScript *)res)->resultZ); +#pragma GCC diagnostic pop } /*********************************************************************************************************************************** @@ -358,7 +368,7 @@ Shim for PQntuples() int PQntuples(const PGresult *res) { - return hrnPqScriptRun(HRN_PQ_NTUPLES, NULL, (HrnPqScript *)res)->resultInt; + return hrnPqScriptRun(HRN_PQ_NTUPLES, NULL, (const HrnPqScript *)res)->resultInt; } /*********************************************************************************************************************************** @@ -367,7 +377,7 @@ Shim for PQnfields() int PQnfields(const PGresult *res) { - return hrnPqScriptRun(HRN_PQ_NFIELDS, NULL, (HrnPqScript *)res)->resultInt; + return hrnPqScriptRun(HRN_PQ_NFIELDS, NULL, (const HrnPqScript *)res)->resultInt; } /*********************************************************************************************************************************** @@ -378,7 +388,7 @@ PQgetisnull(const PGresult *res, int tup_num, int field_num) { return hrnPqScriptRun( HRN_PQ_GETISNULL, varLstAdd(varLstAdd(varLstNew(), varNewInt(tup_num)), varNewInt(field_num)), - (HrnPqScript *)res)->resultInt; + (const HrnPqScript *)res)->resultInt; } /*********************************************************************************************************************************** @@ -387,7 +397,7 @@ Shim for PQftype() Oid PQftype(const PGresult *res, int field_num) { - return (Oid)hrnPqScriptRun(HRN_PQ_FTYPE, varLstAdd(varLstNew(), varNewInt(field_num)), (HrnPqScript *)res)->resultInt; + return (Oid)hrnPqScriptRun(HRN_PQ_FTYPE, varLstAdd(varLstNew(), varNewInt(field_num)), (const HrnPqScript *)res)->resultInt; } /*********************************************************************************************************************************** @@ -396,8 +406,16 @@ Shim for PQgetvalue() char * PQgetvalue(const PGresult *res, int tup_num, int field_num) { - return (char *)hrnPqScriptRun( - HRN_PQ_GETVALUE, varLstAdd(varLstAdd(varLstNew(), varNewInt(tup_num)), varNewInt(field_num)), (HrnPqScript *)res)->resultZ; + // Const values are used for testing but the function requires them to be returned non-const. This should be safe because the + // value is never modified by the calling function. If that changes, there will be a segfault during testing. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + return UNCONSTIFY( + char *, + hrnPqScriptRun( + HRN_PQ_GETVALUE, varLstAdd(varLstAdd(varLstNew(), varNewInt(tup_num)), varNewInt(field_num)), + (const HrnPqScript *)res)->resultZ); +#pragma GCC diagnostic pop } /*********************************************************************************************************************************** diff --git a/test/src/common/harnessServer.c b/test/src/common/harnessServer.c index adbca4077..71b74a455 100644 --- a/test/src/common/harnessServer.c +++ b/test/src/common/harnessServer.c @@ -349,14 +349,14 @@ hrnServerRun(IoRead *const read, const HrnServerProtocol protocol, const unsigne TRY_END(); // Treat any ? characters as wildcards so variable elements (e.g. auth hashes) can be ignored - String *actual = strNewBuf(buffer); - - for (unsigned int actualIdx = 0; actualIdx < strSize(actual); actualIdx++) + for (unsigned int bufferIdx = 0; bufferIdx < bufUsed(buffer); bufferIdx++) { - if (strZ(expected)[actualIdx] == '?') - ((char *)strZ(actual))[actualIdx] = '?'; + if (strZ(expected)[bufferIdx] == '?') + bufPtr(buffer)[bufferIdx] = '?'; } + const String *actual = strNewBuf(buffer); + // Error if actual does not match expected if (!strEq(actual, expected)) THROW_FMT(AssertError, "server expected:\n'%s' but got:\n'%s'", strZ(expected), strZ(actual)); diff --git a/test/src/common/harnessTest.c b/test/src/common/harnessTest.c index cfe7b7295..e0deb0b4c 100644 --- a/test/src/common/harnessTest.c +++ b/test/src/common/harnessTest.c @@ -298,12 +298,12 @@ hrnDiff(const char *expected, const char *actual) // Write expected file char expectedFile[1024]; snprintf(expectedFile, sizeof(expectedFile), "%s/diff.expected", hrnPath()); - hrnFileWrite(expectedFile, (unsigned char *)expected, strlen(expected)); + hrnFileWrite(expectedFile, (const unsigned char *)expected, strlen(expected)); // Write actual file char actualFile[1024]; snprintf(actualFile, sizeof(actualFile), "%s/diff.actual", hrnPath()); - hrnFileWrite(actualFile, (unsigned char *)actual, strlen(actual)); + hrnFileWrite(actualFile, (const unsigned char *)actual, strlen(actual)); // Perform diff char command[2560]; diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c index 603bde3f9..34a0a3c9d 100644 --- a/test/src/module/command/backupTest.c +++ b/test/src/module/command/backupTest.c @@ -2170,9 +2170,8 @@ testRun(void) // Create a backup manifest that looks like a halted backup manifest Manifest *manifestResume = manifestNewBuild( storagePg(), PG_VERSION_95, hrnPgCatalogVersion(PG_VERSION_95), 0, true, false, false, false, NULL, NULL, NULL); - ManifestData *manifestResumeData = (ManifestData *)manifestData(manifestResume); - manifestResumeData->backupType = backupTypeFull; + manifestResume->pub.data.backupType = backupTypeFull; const String *resumeLabel = backupLabelCreate(backupTypeFull, NULL, backupTimeStart); manifestBackupLabelSet(manifestResume, resumeLabel); @@ -2249,10 +2248,9 @@ testRun(void) // Create a backup manifest that looks like a halted backup manifest Manifest *manifestResume = manifestNewBuild( storagePg(), PG_VERSION_95, hrnPgCatalogVersion(PG_VERSION_95), 0, true, false, false, false, NULL, NULL, NULL); - ManifestData *manifestResumeData = (ManifestData *)manifestData(manifestResume); - manifestResumeData->backupType = backupTypeFull; - manifestResumeData->backupOptionCompressType = compressTypeGz; + manifestResume->pub.data.backupType = backupTypeFull; + manifestResume->pub.data.backupOptionCompressType = compressTypeGz; const String *resumeLabel = backupLabelCreate(backupTypeFull, NULL, backupTimeStart); manifestBackupLabelSet(manifestResume, resumeLabel); @@ -2314,6 +2312,8 @@ testRun(void) storageRepoWrite(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, strZ(resumeLabel))))); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" // Disable storageFeaturePath so paths will not be created before files are copied ((Storage *)storageRepoWrite())->pub.interface.feature ^= 1 << storageFeaturePath; @@ -2327,6 +2327,7 @@ testRun(void) // Enable storage features ((Storage *)storageRepoWrite())->pub.interface.feature |= 1 << storageFeaturePath; ((Storage *)storageRepoWrite())->pub.interface.feature |= 1 << storageFeaturePathSync; +#pragma GCC diagnostic pop TEST_RESULT_LOG( "P00 INFO: execute exclusive backup start: backup begins after the next regular checkpoint completes\n" @@ -2407,9 +2408,8 @@ testRun(void) // Create a backup manifest that looks like a halted backup manifest Manifest *manifestResume = manifestNewBuild( storagePg(), PG_VERSION_95, hrnPgCatalogVersion(PG_VERSION_95), 0, true, false, false, false, NULL, NULL, NULL); - ManifestData *manifestResumeData = (ManifestData *)manifestData(manifestResume); - manifestResumeData->backupOptionCompressType = compressTypeGz; + manifestResume->pub.data.backupOptionCompressType = compressTypeGz; const String *resumeLabel = backupLabelCreate(backupTypeFull, NULL, backupTimeStart - 100000); manifestBackupLabelSet(manifestResume, resumeLabel); strLstAddZ(manifestResume->pub.referenceList, "BOGUS"); @@ -2462,7 +2462,7 @@ testRun(void) strZ(storagePathP(storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/pg_data/pipe", strZ(resumeLabel))))); // Save the resume manifest with full type - manifestResumeData->backupType = backupTypeFull; + manifestResume->pub.data.backupType = backupTypeFull; manifestSave( manifestResume, @@ -2532,7 +2532,7 @@ testRun(void) HRN_STORAGE_REMOVE(storageRepoWrite(), "backup/test1/20191003-105321F/backup.manifest"); // Save the resume manifest with diff type - manifestResumeData->backupType = backupTypeDiff; + manifestResume->pub.data.backupType = backupTypeDiff; manifestSave( manifestResume, @@ -2983,6 +2983,8 @@ testRun(void) zNewFmt("pg1-tblspc/32768/%s/1/5", strZ(pgTablespaceId(PG_VERSION_11, hrnPgCatalogVersion(PG_VERSION_11)))), .timeModified = backupTimeStart); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" // Disable storageFeatureSymLink so tablespace (and latest) symlinks will not be created ((Storage *)storageRepoWrite())->pub.interface.feature ^= 1 << storageFeatureSymLink; @@ -2996,6 +2998,7 @@ testRun(void) // Reset storage features ((Storage *)storageRepoWrite())->pub.interface.feature |= 1 << storageFeatureSymLink; ((Storage *)storageRepoWrite())->pub.interface.feature |= 1 << storageFeatureHardLink; +#pragma GCC diagnostic pop TEST_RESULT_LOG( "P00 INFO: execute non-exclusive backup start: backup begins after the next regular checkpoint completes\n" @@ -3607,7 +3610,7 @@ testRun(void) // Load the previous manifest and null out the checksum-page option to be sure it gets set to false in this backup const String *manifestPriorFile = STRDEF(STORAGE_REPO_BACKUP "/20191103-165320F/" BACKUP_MANIFEST_FILE); Manifest *manifestPrior = manifestNewLoad(storageReadIo(storageNewReadP(storageRepo(), manifestPriorFile))); - ((ManifestData *)manifestData(manifestPrior))->backupOptionChecksumPage = NULL; + manifestPrior->pub.data.backupOptionChecksumPage = NULL; manifestSave(manifestPrior, storageWriteIo(storageNewWriteP(storageRepoWrite(), manifestPriorFile))); // Load options diff --git a/test/src/module/common/encodeTest.c b/test/src/module/common/encodeTest.c index c33c9f5af..f49aae422 100644 --- a/test/src/module/common/encodeTest.c +++ b/test/src/module/common/encodeTest.c @@ -30,17 +30,19 @@ testRun(void) TEST_RESULT_Z(destinationEncode, "c3Ry", "3 character encode"); TEST_RESULT_UINT(encodeToStrSize(encodingBase64, 3), strlen(destinationEncode), "check size"); - encodeToStr(encodingBase64, encode, strlen((char *)encode) - 2, destinationEncode); + encodeToStr(encodingBase64, encode, strlen((const char *)encode) - 2, destinationEncode); TEST_RESULT_Z(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ==", "encode full string"); - TEST_RESULT_UINT(encodeToStrSize(encodingBase64, strlen((char *)encode) - 2), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT( + encodeToStrSize(encodingBase64, strlen((const char *)encode) - 2), strlen(destinationEncode), "check size"); - encodeToStr(encodingBase64, encode, strlen((char *)encode), destinationEncode); + encodeToStr(encodingBase64, encode, strlen((const char *)encode), destinationEncode); TEST_RESULT_Z(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0K", "encode full string with \\r\\n"); - TEST_RESULT_UINT(encodeToStrSize(encodingBase64, strlen((char *)encode)), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT(encodeToStrSize(encodingBase64, strlen((const char *)encode)), strlen(destinationEncode), "check size"); - encodeToStr(encodingBase64, encode, strlen((char *)encode) + 1, destinationEncode); + encodeToStr(encodingBase64, encode, strlen((const char *)encode) + 1, destinationEncode); TEST_RESULT_Z(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0KAA==", "encode full string with \\r\\n and null"); - TEST_RESULT_UINT(encodeToStrSize(encodingBase64, strlen((char *)encode) + 1), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT( + encodeToStrSize(encodingBase64, strlen((const char *)encode) + 1), strlen(destinationEncode), "check size"); // ------------------------------------------------------------------------------------------------------------------------- unsigned char destinationDecode[256]; @@ -48,23 +50,23 @@ testRun(void) memset(destinationDecode, 0xFF, sizeof(destinationDecode)); const char *decode = "c3RyaW5nX3RvX2VuY29kZQ0KAA=="; decodeToBin(encodingBase64, decode, destinationDecode); - TEST_RESULT_Z((char *)destinationDecode, (char *)encode, "full string with \\r\\n and null decode"); - TEST_RESULT_INT(destinationDecode[strlen((char *)encode) + 1], 0xFF, "check for overrun"); - TEST_RESULT_UINT(decodeToBinSize(encodingBase64, decode), strlen((char *)encode) + 1, "check size"); + TEST_RESULT_Z((char *)destinationDecode, (const char *)encode, "full string with \\r\\n and null decode"); + TEST_RESULT_INT(destinationDecode[strlen((const char *)encode) + 1], 0xFF, "check for overrun"); + TEST_RESULT_UINT(decodeToBinSize(encodingBase64, decode), strlen((const char *)encode) + 1, "check size"); memset(destinationDecode, 0xFF, sizeof(destinationDecode)); decode = "c3RyaW5nX3RvX2VuY29kZQ0K"; decodeToBin(encodingBase64, decode, destinationDecode); - TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((char *)encode)), 0, "full string with \\r\\n decode"); - TEST_RESULT_INT(destinationDecode[strlen((char *)encode)], 0xFF, "check for overrun"); - TEST_RESULT_UINT(decodeToBinSize(encodingBase64, decode), strlen((char *)encode), "check size"); + TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((const char *)encode)), 0, "full string with \\r\\n decode"); + TEST_RESULT_INT(destinationDecode[strlen((const char *)encode)], 0xFF, "check for overrun"); + TEST_RESULT_UINT(decodeToBinSize(encodingBase64, decode), strlen((const char *)encode), "check size"); memset(destinationDecode, 0xFF, sizeof(destinationDecode)); decode = "c3RyaW5nX3RvX2VuY29kZQ=="; decodeToBin(encodingBase64, decode, destinationDecode); - TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((char *)encode) - 2), 0, "full string decode"); - TEST_RESULT_INT(destinationDecode[strlen((char *)encode) - 2], 0xFF, "check for overrun"); - TEST_RESULT_UINT(decodeToBinSize(encodingBase64, decode), strlen((char *)encode) - 2, "check size"); + TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((const char *)encode) - 2), 0, "full string decode"); + TEST_RESULT_INT(destinationDecode[strlen((const char *)encode) - 2], 0xFF, "check for overrun"); + TEST_RESULT_UINT(decodeToBinSize(encodingBase64, decode), strlen((const char *)encode) - 2, "check size"); memset(destinationDecode, 0xFF, sizeof(destinationDecode)); decode = "c3Ry"; @@ -122,17 +124,19 @@ testRun(void) TEST_RESULT_Z(destinationEncode, "c3Ry", "3 character encode"); TEST_RESULT_UINT(encodeToStrSize(encodingBase64Url, 3), strlen(destinationEncode), "check size"); - encodeToStr(encodingBase64Url, encode, strlen((char *)encode) - 2, destinationEncode); + encodeToStr(encodingBase64Url, encode, strlen((const char *)encode) - 2, destinationEncode); TEST_RESULT_Z(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ", "encode full string"); - TEST_RESULT_UINT(encodeToStrSize(encodingBase64Url, strlen((char *)encode) - 2), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT( + encodeToStrSize(encodingBase64Url, strlen((const char *)encode) - 2), strlen(destinationEncode), "check size"); - encodeToStr(encodingBase64Url, encode, strlen((char *)encode), destinationEncode); + encodeToStr(encodingBase64Url, encode, strlen((const char *)encode), destinationEncode); TEST_RESULT_Z(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0K", "encode full string with \\r\\n"); - TEST_RESULT_UINT(encodeToStrSize(encodingBase64Url, strlen((char *)encode)), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT(encodeToStrSize(encodingBase64Url, strlen((const char *)encode)), strlen(destinationEncode), "check size"); - encodeToStr(encodingBase64Url, encode, strlen((char *)encode) + 1, destinationEncode); + encodeToStr(encodingBase64Url, encode, strlen((const char *)encode) + 1, destinationEncode); TEST_RESULT_Z(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0KAA", "encode full string with \\r\\n and null"); - TEST_RESULT_UINT(encodeToStrSize(encodingBase64Url, strlen((char *)encode) + 1), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT( + encodeToStrSize(encodingBase64Url, strlen((const char *)encode) + 1), strlen(destinationEncode), "check size"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("decode unsupported"); @@ -155,13 +159,13 @@ testRun(void) TEST_RESULT_Z(destinationEncode, "73", "1 character encode"); TEST_RESULT_UINT(encodeToStrSize(encodingHex, 1), strlen(destinationEncode), "check size"); - encodeToStr(encodingHex, encode, strlen((char *)encode), destinationEncode); + encodeToStr(encodingHex, encode, strlen((const char *)encode), destinationEncode); TEST_RESULT_Z(destinationEncode, "737472696e675f746f5f656e636f64650d0a", "encode full string with \\r\\n"); - TEST_RESULT_UINT(encodeToStrSize(encodingHex, strlen((char *)encode)), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT(encodeToStrSize(encodingHex, strlen((const char *)encode)), strlen(destinationEncode), "check size"); - encodeToStr(encodingHex, encode, strlen((char *)encode) + 1, destinationEncode); + encodeToStr(encodingHex, encode, strlen((const char *)encode) + 1, destinationEncode); TEST_RESULT_Z(destinationEncode, "737472696e675f746f5f656e636f64650d0a00", "encode full string with \\r\\n and null"); - TEST_RESULT_UINT(encodeToStrSize(encodingHex, strlen((char *)encode) + 1), strlen(destinationEncode), "check size"); + TEST_RESULT_UINT(encodeToStrSize(encodingHex, strlen((const char *)encode) + 1), strlen(destinationEncode), "check size"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("decode"); @@ -171,9 +175,9 @@ testRun(void) memset(destinationDecode, 0xFF, sizeof(destinationDecode)); const char *decode = "737472696e675f746f5f656e636f64650d0a00"; decodeToBin(encodingHex, decode, destinationDecode); - TEST_RESULT_Z((char *)destinationDecode, (char *)encode, "full string with \\r\\n and null decode"); - TEST_RESULT_INT(destinationDecode[strlen((char *)encode) + 1], 0xFF, "check for overrun"); - TEST_RESULT_UINT(decodeToBinSize(encodingHex, decode), strlen((char *)encode) + 1, "check size"); + TEST_RESULT_Z((char *)destinationDecode, (const char *)encode, "full string with \\r\\n and null decode"); + TEST_RESULT_INT(destinationDecode[strlen((const char *)encode) + 1], 0xFF, "check for overrun"); + TEST_RESULT_UINT(decodeToBinSize(encodingHex, decode), strlen((const char *)encode) + 1, "check size"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("decode/encode with mixed case"); diff --git a/test/src/module/common/typeListTest.c b/test/src/module/common/typeListTest.c index c80d258e6..b333b61d0 100644 --- a/test/src/module/common/typeListTest.c +++ b/test/src/module/common/typeListTest.c @@ -9,7 +9,7 @@ Test sort comparator static int testComparator(const void *item1, const void *item2) { - return LST_COMPARATOR_CMP(*(int *)item1, *(int *)item2); + return LST_COMPARATOR_CMP(*(const int *)item1, *(const int *)item2); } /*********************************************************************************************************************************** @@ -56,7 +56,7 @@ testRun(void) TEST_RESULT_PTR(lstFindDefault(list, &string3, (void *)1), (void *)1, " find string3 returns default"); TEST_RESULT_BOOL(lstExists(list, &string3), false, " string3 does not exist"); TEST_RESULT_STR_Z(*(String **)lstFind(list, &string2), "string2", " find string2"); - TEST_RESULT_STR_Z(*(String **)lstFindDefault(list, &string2, NULL), "string2", " find string2 no default"); + TEST_RESULT_STR_Z(*(const String *const *)lstFindDefault(list, &string2, NULL), "string2", " find string2 no default"); TEST_RESULT_BOOL(lstExists(list, &string2), true, " string2 exists"); TEST_RESULT_BOOL(lstRemove(list, &string2), true, " remove string2"); diff --git a/test/src/module/performance/typeTest.c b/test/src/module/performance/typeTest.c index b13837005..f7ab13ff2 100644 --- a/test/src/module/performance/typeTest.c +++ b/test/src/module/performance/typeTest.c @@ -31,7 +31,7 @@ Test sort comparator static int testComparator(const void *item1, const void *item2) { - return LST_COMPARATOR_CMP(*(int *)item1, *(int *)item2); + return LST_COMPARATOR_CMP(*(const int *)item1, *(const int *)item2); } /*********************************************************************************************************************************** diff --git a/test/src/module/storage/sftpTest.c b/test/src/module/storage/sftpTest.c index 7b6a99ad1..8d3e159ed 100644 --- a/test/src/module/storage/sftpTest.c +++ b/test/src/module/storage/sftpTest.c @@ -121,8 +121,7 @@ testRun(void) {.function = HRNLIBSSH2_SESSION_HANDSHAKE, .param = HANDSHAKE_PARAM, .resultInt = LIBSSH2_ERROR_EAGAIN}, {.function = HRNLIBSSH2_SESSION_BLOCK_DIRECTIONS, .resultInt = SSH2_BLOCK_WRITING}, {.function = HRNLIBSSH2_SESSION_HANDSHAKE, .param = HANDSHAKE_PARAM, .resultInt = LIBSSH2_ERROR_BAD_SOCKET}, - {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .resultInt = LIBSSH2_ERROR_BAD_SOCKET, - .errMsg = (char *)"Bad socket provided"}, + {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .resultInt = LIBSSH2_ERROR_BAD_SOCKET, .errMsg = "Bad socket provided"}, {.function = NULL} }); @@ -296,7 +295,7 @@ testRun(void) {.function = HRNLIBSSH2_KNOWNHOST_INIT, .resultNull = true}, {.function = HRNLIBSSH2_SESSION_LAST_ERRNO, .resultInt = LIBSSH2_ERROR_ALLOC}, {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .resultInt = LIBSSH2_ERROR_ALLOC, - .errMsg = (char *)"Unable to allocate memory for known-hosts collection"}, + .errMsg = "Unable to allocate memory for known-hosts collection"}, {.function = NULL} }); @@ -851,7 +850,7 @@ testRun(void) {.function = HRNLIBSSH2_KNOWNHOST_INIT, .resultNull = true}, {.function = HRNLIBSSH2_SESSION_LAST_ERRNO, .resultInt = LIBSSH2_ERROR_ALLOC}, {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .resultInt = LIBSSH2_ERROR_ALLOC, - .errMsg = (char *)"Unable to allocate memory for known-hosts collection"}, + .errMsg = "Unable to allocate memory for known-hosts collection"}, {.function = HRNLIBSSH2_USERAUTH_PUBLICKEY_FROMFILE_EX, .param = "[\"" TEST_USER "\"," TEST_USER_LEN ",\"" KEYPUB_CSTR "\",\"" KEYPRIV_CSTR "\",null]", .resultInt = 0}, @@ -917,7 +916,7 @@ testRun(void) .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_KNOWNHOST_READFILE, .param = "[\"" KNOWNHOSTS_FILE_CSTR "\",1]", .resultInt = LIBSSH2_ERROR_FILE}, - {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = (char *)"Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, + {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = "Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_USERAUTH_PUBLICKEY_FROMFILE_EX, .param = "[\"" TEST_USER "\"," TEST_USER_LEN ",\"" KEYPUB_CSTR "\",\"" KEYPRIV_CSTR "\",null]", .resultInt = 0}, @@ -986,7 +985,7 @@ testRun(void) .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_KNOWNHOST_READFILE, .param = "[\"" KNOWNHOSTS_FILE_CSTR "\",1]", .resultInt = LIBSSH2_ERROR_FILE}, - {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = (char *)"Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, + {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = "Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_USERAUTH_PUBLICKEY_FROMFILE_EX, .param = "[\"" TEST_USER "\"," TEST_USER_LEN ",\"" KEYPUB_CSTR "\",\"" KEYPRIV_CSTR "\",null]", .resultInt = 0}, @@ -1038,7 +1037,7 @@ testRun(void) {.function = HRNLIBSSH2_KNOWNHOST_INIT}, {.function = HRNLIBSSH2_KNOWNHOST_READFILE, .param = "[\"" KNOWNHOSTS_FILE_CSTR "\",1]", .resultInt = LIBSSH2_ERROR_KNOWN_HOSTS}, - {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = (char *)"Failed to parse known hosts file", + {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = "Failed to parse known hosts file", .resultInt = LIBSSH2_ERROR_KNOWN_HOSTS}, {.function = HRNLIBSSH2_USERAUTH_PUBLICKEY_FROMFILE_EX, .param = "[\"" TEST_USER "\"," TEST_USER_LEN ",\"" KEYPUB_CSTR "\",\"" KEYPRIV_CSTR "\",null]", @@ -1084,10 +1083,10 @@ testRun(void) .resultInt = LIBSSH2_ERROR_NONE}, {.function = HRNLIBSSH2_KNOWNHOST_READFILE, .param = "[\"" KNOWNHOSTS2_FILE_CSTR "\",1]", .resultInt = LIBSSH2_ERROR_FILE}, - {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = (char *)"Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, + {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = "Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_KNOWNHOST_READFILE, .param = "[\"" ETC_KNOWNHOSTS_FILE_CSTR "\",1]", .resultInt = LIBSSH2_ERROR_FILE}, - {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = (char *)"Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, + {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .errMsg = "Failed to open file", .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_KNOWNHOST_READFILE, .param = "[\"" ETC_KNOWNHOSTS2_FILE_CSTR "\",1]", .resultInt = LIBSSH2_ERROR_FILE}, {.function = HRNLIBSSH2_SESSION_LAST_ERROR, .resultInt = LIBSSH2_ERROR_FILE},