aboutsummaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-10-04 08:40:39 -0400
committerGitHub <noreply@github.com>2024-10-04 08:40:39 -0400
commitd7e3deba72703ad36c497f5becf6772ca00a0d6d (patch)
treeeff3b2ec3dcc31126041529c8e00a714997f2d7b /src/str.c
parent9691ccf51b3efd8113e9620c4afa8b5382d7f161 (diff)
parentf0ba8cd378a460f927644e41f49be95d0e956f81 (diff)
downloadstasis-d7e3deba72703ad36c497f5becf6772ca00a0d6d.tar.gz
Merge pull request #46 from jhunkeler/split-delivery-code
Add multiprocessing / Split delivery code
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/str.c b/src/str.c
index 6afbf73..56ea893 100644
--- a/src/str.c
+++ b/src/str.c
@@ -223,21 +223,35 @@ char *join_ex(char *separator, ...) {
}
char *substring_between(char *sptr, const char *delims) {
+ char delim_open[255] = {0};
+ char delim_close[255] = {0};
if (sptr == NULL || delims == NULL) {
return NULL;
}
// Ensure we have enough delimiters to continue
size_t delim_count = strlen(delims);
- if (delim_count < 2 || delim_count % 2) {
+ if (delim_count < 2 || delim_count % 2 || (delim_count > (sizeof(delim_open) - 1)) != 0) {
return NULL;
}
+ size_t delim_take = delim_count / 2;
- char delim_open[255] = {0};
- strncpy(delim_open, delims, delim_count / 2);
+ // How else am I supposed to consume the first and last n chars of the string? Give me a break.
+ // warning: ‘__builtin___strncpy_chk’ specified bound depends on the length of the source argument
+ // ---
+ //strncpy(delim_open, delims, delim_take);
+ size_t i = 0;
+ while (i < delim_take && i < sizeof(delim_open)) {
+ delim_open[i] = delims[i];
+ i++;
+ }
- char delim_close[255] = {0};
- strcpy(delim_close, &delims[delim_count / 2]);
+ //strncpy(delim_close, &delims[delim_take], delim_take);
+ i = 0;
+ while (i < delim_take && i < sizeof(delim_close)) {
+ delim_close[i] = delims[i + delim_take];
+ i++;
+ }
// Create pointers to the delimiters
char *start = strstr(sptr, delim_open);