aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-01-26 00:33:55 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-01-26 00:33:55 +0100
commit70ffd8c58bbfdf009a9370ba15cc3568722998f7 (patch)
treebfa71f67e53f49087d990790c75c1cf983c1d7eb
parent43b9748844eb2d9f4ede0f25537e4a318b341204 (diff)
downloadPROJ-70ffd8c58bbfdf009a9370ba15cc3568722998f7.tar.gz
PROJ-70ffd8c58bbfdf009a9370ba15cc3568722998f7.zip
string_to_paralist(): simplify so that it is obvious to cppcheck that null-ptr dereference cannot happen
-rw-r--r--src/init.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 19fcf47b..c1683285 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -48,25 +48,23 @@ static paralist *string_to_paralist (PJ_CONTEXT *ctx, char *definition) {
Convert a string (presumably originating from get_init_string) to a paralist.
***************************************************************************************/
const char *c = definition;
- paralist *first = nullptr, *next = nullptr;
+ paralist *first = nullptr, *last = nullptr;
while (*c) {
/* Keep a handle to the start of the list, so we have something to return */
- if (nullptr==first)
- first = next = pj_mkparam_ws (c, &c);
- else
- next = next->next = pj_mkparam_ws (c, &c);
- if (nullptr==next) {
+ auto param = pj_mkparam_ws (c, &c);
+ if (nullptr==param) {
pj_dealloc_params (ctx, first, ENOMEM);
return nullptr;
}
+ if (nullptr==last) {
+ first = param;
+ }
+ else {
+ last->next = param;
+ }
+ last = param;
}
-
- if( next == nullptr )
- return nullptr;
-
- /* Terminate list and return */
- next->next = nullptr;
return first;
}