Commit graph

350 commits

Author SHA1 Message Date
Björn Svensson
2c06b8d750 Fix Clang compiler warnings
When building using a newer Clang with additional diagnostics
the following warnings are given:
 -Wunused-but-set-variable
 -Wstrict-prototypes
These issues are corrected in this commit.

Reproducable using:
CC="clang-13" CFLAGS="-Wall -pedantic" cmake ..
2023-10-26 12:24:50 +02:00
Björn Svensson
c105117b40
Use PCRE2 instead of PCRE (#153)
PCRE is now at end of life and is no longer actively maintained.
Lift the dependency to the next major version, i.e. PCRE2.

Implementation notes:
- Removed the pcre study option since:
  "The new API ... was simplified by abolishing the separate "study" optimizing
  function; in PCRE2, patterns are automatically optimized where possible."
- If asprintf() fails the content of the 'strp' variable is undefined.
  Lets check the return value and return NULL upon error.
- Pattern and subject can straightforwardly be cast to PCRE2_SPTR since we
  only work with 8-bit code units.
2023-10-23 12:38:24 +02:00
Björn Svensson
9168f7e4d4 Support C23 projects
Don't define true/false/bool when r3 is used by C23 projects
since C23 already has a bool type and predefined constants.
2023-10-23 10:45:18 +02:00
Bjorn Svensson
9b69f38527
Fix leak in r3_tree_insert_pathl_ex() (#150)
Includes a testcase triggering the issue when building with
the leak sanitizer.

Resource leak (CID 355063) found by Coverity,
2022-07-20 13:23:45 +02:00
Björn Svensson
04d52a6dd1 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.
2021-11-10 22:20:46 +01:00
Yo-An Lin
76e2770304
Merge pull request #148 from Nordix/faulty-slug-in-insert-route
Handle incomplete slug pattern when inserting a route
2021-11-05 09:27:52 +08:00
Björn Svensson
2f3e0b01ff Handle incomplete slug in insert route 2021-11-04 20:22:10 +01:00
Björn Svensson
bf11f8e2e6 Remove unused code in memory.c/.h 2021-11-03 21:58:33 +01:00
Björn Svensson
f0dd25bd53 Remove unused memory pool 2021-11-03 21:22:48 +01:00
Yo-An Lin
b13dc8aa6e
Merge pull request #131 from iresty/feature-ipv6
feature: supported to use ipv6 address match route.
2021-10-14 10:31:23 +08:00
Björn Svensson
00ec8b7f2b Correct buffer over-read errors
When inserting multiple routes with common slug patterns
there are reads beyond end of strings.

The scenario is added as a testcase and can be triggered by
the address-sanitizer when built using:
`CFLAGS="-fno-omit-frame-pointer -fsanitize=address" cmake ..`

Indicated as a `buffer-overflow`
2021-10-11 10:19:09 +02:00
Yo-An Lin
d2fcf2f2d4
Merge pull request #135 from fishgege/patch-1
bugfix: insert path success, but get data failed
2021-10-07 22:08:13 +08:00
Björn Svensson
ff1ef2c148 Correcting issue with multiple edges
When `r3_node_find_common_prefix()` searches for the common prefix it
selects the first matched edge, which might not be the best match.

This issue gives memoryleaks which can be viewed in legacy
testcase `check_tree::test_insert_pathl()` by building using:
`CFLAGS="-fno-omit-frame-pointer -fsanitize=leak" cmake ..`
See testcase procedures:
    ret = r3_tree_insert_path(n, "/foo/{id}",  NULL);
    ..
    ret = r3_tree_insert_path(n, "/foo/{idx}/{idy}",  NULL);
    ..
    ret = r3_tree_insert_path(n, "/foo/{idx}/{idh}",  NULL); <-- leaks

Also added a testcase that triggers the problem including a leak for
reproduction on baseline.
2021-09-20 16:55:37 +02:00
董宇
36198aefba
bugfix: insert path success, but get data failed
background : use  r3_tree_insert_pathl_ex to add path,A : abcdefg   B:abc
When the node A already exists, we set B, then  will split the node and make a branch, suboath_len  is 0 
In this case,  branch a  zero len subpath, which tree's data not set
2019-12-15 13:05:49 +08:00
Yuansheng
79fd587615 feature: supported to match ipv6 address. 2019-08-01 21:38:14 -04:00
Yuansheng
1b9e007dfc bugfix: make a try for endpoint. 2019-07-21 08:46:37 -04:00
Yuansheng
81f77ffe5a test: added test cases. 2019-07-21 08:46:37 -04:00
Yuansheng
0d70b8f5de bugfix: the end matching length is 0. 2019-07-21 08:46:37 -04:00
Yuansheng
db91289ab6 change: rename OP_EXPECT_NOLINEBREAKS to OP_GREEDY_ANY. 2019-07-20 10:52:56 -04:00
Yuansheng
d516237aab optimize: optimized pattern .*, which can be used prefix matching. 2019-07-20 10:52:56 -04:00
Yo-An Lin
41685d402d
Merge pull request #129 from iresty/make-warning
change: avoided compiling warning.
2019-07-20 18:00:48 +08:00
Yuansheng
fdc698f924 change: avoided compiling warning message. 2019-07-20 07:12:37 +08:00
Yuansheng
43666a1183 feature: supported to match http scheme. 2019-06-26 23:06:32 +08:00
Yuansheng
8e18a995d8 make: avoided the warning message when do make.
change: code style, delete some useless spaces(visual code).

eg:

warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result
2019-06-21 10:45:54 +08:00
Yuansheng
848b8efdca feature: supported to match remote ip address. 2019-06-19 23:36:37 -04:00
Yuansheng
4ab222a308 feature: supported wildcard match way for host. 2019-06-19 10:07:14 -04:00
Michael Steinert
b3dbf75da5 Remove zmalloc dependency
Zmalloc comes from Redis. It's purpose is to track total allocations so
that a maximum can be set. For more information see the following links:

https://groups.google.com/forum/#!topic/redis-db/dPRdpowqJsY
https://stackoverflow.com/questions/22729730/when-would-one-use-malloc-over-zmalloc

This allocator is slower, not needed, and conflicts with Zlib (when
linking statically). This patch removes Zmalloc in favor of the system
allocator. Application developers can still choose to override the
allocator in their applications, e.g. Jemalloc, TCMalloc, etc.

Fixes #104
2018-07-10 08:20:46 -05:00
Michael Steinert
d1c06cd3e9 Cleanup CMake build files 2018-07-05 11:43:22 -05:00
Michael Steinert
2be2a08750 Fix -Wincompatible-pointer-types warning 2018-07-05 11:43:22 -05:00
Michael Steinert
081ccb2bde Fix issues with check_tree test
This patch fixes a few issues in the check_tree test:

* Fix various memory leaks in test code
* Fix a double-free in test code
* Fix a memory leak in r3_tree_compile_patterns

One memory leak remains in the library code but it isn't obvious to me
how to fix it at the moment.
2018-07-05 09:58:20 -05:00
Martijn Otto
2f96c59929 Further WIP, got the tests to link against pthread (was broken due to pkg-config not specifying -pthread as -lpthread and cmake thus not recognizing it as a library) 2018-02-24 17:45:15 +01:00
Martijn Otto
59d182b1c1 Use the generated config.h instead to enable feature macros 2018-02-21 15:57:25 +01:00
Martijn Otto
1eeff1598a Fix declaration of memset 2018-02-21 10:04:07 +01:00
Martijn Otto
55de164023 Set the feature test macro before including the header to enable non-standard functions used by libr3 2018-02-21 09:49:54 +01:00
Martijn Otto
8d0b90f6e1 Remove unused variables 2018-02-21 09:14:31 +01:00
Martijn Otto
5cab368af2 Add extra parenthesis around branched assignments 2018-02-21 09:11:53 +01:00
Martijn Otto
021c54308a Fix const correctness warnings 2018-02-20 18:18:43 +01:00
c9s
cefefb239a Fix fprintf warning 2016-04-05 16:59:27 +08:00
karantin2020
9411039fce Router match logic corrected 2016-03-26 23:32:37 +05:00
karantin2020
ffc9e8571b Added memory files 2016-03-26 21:34:07 +05:00
karantin2020
75438ef3d3 Changed r3 memory model, made few optimizing 2016-03-22 07:23:37 +05:00
karantin2020
40e0e1c2a0 Changed slug parsing 2016-03-08 14:51:42 +05:00
karantin2020
400768394d Added slug parser and repaired few memory leaks 2016-03-08 11:19:54 +05:00
c9s
c609003c95 optimize c flags for development/production mode 2015-11-21 10:39:49 +08:00
c9s
daee40756c Add -O2 flag as default 2015-11-18 14:46:18 +08:00
c9s
03031e02aa Fix r3 json writer 2015-11-18 14:27:28 +08:00
c9s
c3ef959539 Add route namespace
Summary:

    type route now becomes R3Route

Related issue #63
2015-11-18 14:16:26 +08:00
c9s
49ffb454f7 Add namespace for node/edge structs
node => R3Node
edge => R3Edge

Related issue #63
2015-11-18 12:53:46 +08:00
c9s
ef55fb9cdb Another fix for stdbool types 2015-11-17 21:43:10 +08:00
c9s
1f1ab15cdd Fix for stdbool type 2015-11-17 21:40:21 +08:00