fixed broken test with constant ov array size set to 30

This commit is contained in:
simon-p-r 2018-09-17 19:46:24 +01:00
parent 3ae3da52c7
commit 07443aa8a8
No known key found for this signature in database
GPG key ID: 242BD4242D286274
3 changed files with 31 additions and 8 deletions

View file

@ -0,0 +1,25 @@
Building with CMAKE on Windows using VCPKG
=======================================
This document describes how to compile, build and install libr3 on Windows using CMake, MSVC compiler and VCPKG
VCPKG can be installed from
https://github.com/Microsoft/vcpkg
Once VCPKG is installed you must install libcheck and pcre before running the folloiwing command to configure build
cmake -H"." -B"<BUILD_DIRECTORY>" -G"<GENERATOR_NAME>" -DCMAKE_TOOLCHAIN_FILE=<VCPKG_TOOLCHAIN_FILE> -DVCPKG_TARGET_TRIPLET=<VCPKG_TARGET_TRIPLET>
Then to perform build
cmake --build -B"<BUILD_DIRECTORY>" --target ALL_BUILD --config "<CMAKE_BUILD_TYPE>"
Then to run tests, you must copy pcre.dll and pcre.pdb file to output directory prior to running tests
cmake --build -B"<BUILD_DIRECTORY>" --target RUN_TESTS --config "<CMAKE_BUILD_TYPE>"
Window build is currently WIP.

View file

@ -8,6 +8,8 @@
// PCRE // PCRE
#include <pcre.h> #include <pcre.h>
#define MAX_SUBSTRINGS 30
#include "r3.h" #include "r3.h"
#include "r3_slug.h" #include "r3_slug.h"
#include "slug.h" #include "slug.h"
@ -329,7 +331,7 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l
info("COMPARE PCRE_PATTERN\n"); info("COMPARE PCRE_PATTERN\n");
const char *substring_start = 0; const char *substring_start = 0;
int substring_length = 0; int substring_length = 0;
int *ov = malloc(sizeof(int) * n->ov_cnt); int ov[MAX_SUBSTRINGS];
int rc; int rc;
info("pcre matching %s on %s\n", n->combined_pattern, path); info("pcre matching %s on %s\n", n->combined_pattern, path);
@ -360,7 +362,6 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l
break; break;
} }
#endif #endif
free(ov);
return NULL; return NULL;
} }
@ -388,7 +389,6 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l
str_array_append(&entry->vars, substring_start, substring_length); str_array_append(&entry->vars, substring_start, substring_length);
} }
free(ov);
// since restlen == 0 return the edge quickly. // since restlen == 0 return the edge quickly.
return e->child && e->child->endpoint ? e->child : NULL; return e->child && e->child->endpoint ? e->child : NULL;
} }
@ -415,12 +415,10 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l
str_array_append(&entry->vars , substring_start, substring_length); str_array_append(&entry->vars , substring_start, substring_length);
} }
free(ov);
// get the length of orginal string: $0 // get the length of orginal string: $0
return r3_tree_matchl( e->child, path + (ov[1] - ov[0]), restlen, entry); return r3_tree_matchl( e->child, path + (ov[1] - ov[0]), restlen, entry);
} }
// does not match // does not match
free(ov);
return NULL; return NULL;
} }

View file

@ -305,7 +305,7 @@ START_TEST (test_compile)
entry = match_entry_createl( "/foo/xxx" , strlen("/foo/xxx") ); entry = match_entry_createl( "/foo/xxx" , strlen("/foo/xxx") );
m = r3_tree_matchl( n , "/foo/xxx", strlen("/foo/xxx"), entry); m = r3_tree_matchl( n , "/foo/xxx", strlen("/foo/xxx"), entry);
// ck_assert( m ); ck_assert( m );
match_entry_free(entry); match_entry_free(entry);
entry = match_entry_createl( "/some_id" , strlen("/some_id") ); entry = match_entry_createl( "/some_id" , strlen("/some_id") );
@ -472,8 +472,8 @@ START_TEST (test_pcre_patterns_insert_2)
// r3_tree_dump(n, 0); // r3_tree_dump(n, 0);
R3Node *matched; R3Node *matched;
matched = r3_tree_match(n, "/post/11/22", NULL); matched = r3_tree_match(n, "/post/11/22", NULL);
// ck_assert(matched); ck_assert(matched);
// ck_assert(matched->endpoint > 0); ck_assert(matched->endpoint > 0);
r3_tree_free(n); r3_tree_free(n);
} }