From 04d52a6dd199d180196895e3d21d98c976fabeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Mon, 8 Nov 2021 14:49:12 +0100 Subject: [PATCH] Fix Coverity warning The return value was checked on all calls to r3_slug_find_placeholder() except in one place, which triggered a Coverity warning. This adds a check (assert), and enables the other asserts for non-debug builds to catch segmentation faults early. --- src/node.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/node.c b/src/node.c index 399e672..46a70b2 100644 --- a/src/node.c +++ b/src/node.c @@ -720,18 +720,11 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa if ( slug_cnt > 1 ) { unsigned int slug_len; const char *p = r3_slug_find_placeholder(path, path_len, &slug_len); - -#ifdef DEBUG assert(p); -#endif // find the next one '{', then break there - if(p) { - p = r3_slug_find_placeholder(p + slug_len + 1, path_len - slug_len - 1, NULL); - } -#ifdef DEBUG + p = r3_slug_find_placeholder(p + slug_len + 1, path_len - slug_len - 1, NULL); assert(p); -#endif // insert the first one edge, and break at "p" R3Node * child = r3_tree_create(3); @@ -745,6 +738,7 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa // there is one slug, let's see if it's optimiz-able by opcode unsigned int slug_len = 0; const char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len); + assert(slug_p); unsigned int slug_pattern_len = 0; const char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);