pgbackrest.git / summary / log / commit / refs

commit    cebcb3f027d2a95f5b350df113efef78d449c72f
Author:   David Steele <david@pgmasters.net>
Date:     Thu Jan 10 07:49:28 2019 +0000

    Null-terminate list returned by strLstPtr().
    
    The null-terminator is required by many C functions that accept a string list so just add it in all cases rather than making it optional.


doc/xml/release.xml | 4 ++++ src/common/type/stringList.c | 8 +++++--- test/src/module/common/typeStringTest.c | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index a4df1f1ab..cec04ecb4 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -29,6 +29,10 @@ <p>Ignore <id>SIGPIPE</id> signals and check <id>EPIPE</id> result instead.</p> </release-item> + <release-item> + <p>Null-terminate list returned by <code>strLstPtr()</code>.</p> + </release-item> + <release-item> <p>Rename <code>common/io/handle</code> module to <code>common/io/handleWrite</code>.</p> </release-item> diff --git a/src/common/type/stringList.c b/src/common/type/stringList.c index accf6bcd3..154471e55 100644 --- a/src/common/type/stringList.c +++ b/src/common/type/stringList.c @@ -486,8 +486,8 @@ strLstMove(StringList *this, MemContext *parentNew) } /*********************************************************************************************************************************** -Return an array of pointers to the zero-terminated strings in this list. DO NOT override const and modify any of the strings in -this array, though it is OK to modify the array itself. +Return a null-terminated array of pointers to the zero-terminated strings in this list. DO NOT override const and modify any of the +strings in this array, though it is OK to modify the array itself. ***********************************************************************************************************************************/ const char ** strLstPtr(const StringList *this) @@ -498,7 +498,7 @@ strLstPtr(const StringList *this) FUNCTION_TEST_ASSERT(this != NULL); FUNCTION_TEST_END(); - const char **list = memNew(strLstSize(this) * sizeof(char *)); + const char **list = memNew((strLstSize(this) + 1) * sizeof(char *)); for (unsigned int listIdx = 0; listIdx < strLstSize(this); listIdx++) { @@ -508,6 +508,8 @@ strLstPtr(const StringList *this) list[listIdx] = strPtr(strLstGet(this, listIdx)); } + list[strLstSize(this)] = NULL; + FUNCTION_TEST_RESULT(CONST_CHARPP, list); } diff --git a/test/src/module/common/typeStringTest.c b/test/src/module/common/typeStringTest.c index eedbf0cf2..169814618 100644 --- a/test/src/module/common/typeStringTest.c +++ b/test/src/module/common/typeStringTest.c @@ -335,6 +335,8 @@ testRun(void) TEST_RESULT_STR(szList[listIdx], strPtr(strNewFmt("STR%02u", listIdx)), "check item %u", listIdx); } + TEST_RESULT_PTR(szList[strLstSize(list)], NULL, "check null terminator"); + strLstFree(list); } [parent: f8a9fc203909]