mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-06 01:47:28 +02:00
Fix length argument to pcre2_substitute()
This commit is contained in:
parent
b0d2dd835d
commit
2f8f463a46
@ -85,7 +85,7 @@ unicode.o: unicode.c unicode.h boxes.h tools.h config.h
|
|||||||
shape.o: shape.c shape.h boxes.h tools.h config.h
|
shape.o: shape.c shape.h boxes.h tools.h config.h
|
||||||
generate.o: generate.c generate.h boxes.h shape.h tools.h unicode.h config.h
|
generate.o: generate.c generate.h boxes.h shape.h tools.h unicode.h config.h
|
||||||
remove.o: remove.c remove.h boxes.h shape.h tools.h unicode.h config.h
|
remove.o: remove.c remove.h boxes.h shape.h tools.h unicode.h config.h
|
||||||
regulex.o: regulex.c regulex.h tools.h unicode.h config.h
|
regulex.o: regulex.c regulex.h boxes.h tools.h unicode.h config.h
|
||||||
lex.yy.o: lex.yy.c parser.h tools.h shape.h lexer.h config.h
|
lex.yy.o: lex.yy.c parser.h tools.h shape.h lexer.h config.h
|
||||||
parser.o: parser.c parser.h tools.h shape.h lexer.h config.h
|
parser.o: parser.c parser.h tools.h shape.h lexer.h config.h
|
||||||
misc/getopt.o: misc/getopt.c
|
misc/getopt.o: misc/getopt.c
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "boxes.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "regulex.h"
|
#include "regulex.h"
|
||||||
@ -66,13 +67,15 @@ uint32_t *regex_replace(pcre2_code *search, char *replace, uint32_t *input, cons
|
|||||||
{
|
{
|
||||||
PCRE2_SPTR replacement = u32_strconv_from_arg(replace, config_encoding);
|
PCRE2_SPTR replacement = u32_strconv_from_arg(replace, config_encoding);
|
||||||
if (replacement == NULL) {
|
if (replacement == NULL) {
|
||||||
|
fprintf(stderr, "Failed to convert replacement string to UTF-32 - \"%s\"\n", replace);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t options = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH | PCRE2_SUBSTITUTE_EXTENDED
|
uint32_t options = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH | PCRE2_SUBSTITUTE_EXTENDED
|
||||||
| (global ? PCRE2_SUBSTITUTE_GLOBAL : 0);
|
| (global ? PCRE2_SUBSTITUTE_GLOBAL : 0);
|
||||||
PCRE2_SIZE outlen = input_len * 2; /* estimated length of output buffer in characters, fine if too small */
|
PCRE2_SIZE outlen = input_len * 2; /* estimated length of output buffer in characters, fine if too small */
|
||||||
|
|
||||||
PCRE2_SIZE bufsize = (input_len == 0) ? 16 : outlen;
|
PCRE2_SIZE bufsize = (input_len < 8) ? 16 : outlen;
|
||||||
uint32_t *output = (uint32_t *) malloc(sizeof(uint32_t) * bufsize); /* output buffer */
|
uint32_t *output = (uint32_t *) malloc(sizeof(uint32_t) * bufsize); /* output buffer */
|
||||||
int pcre2_rc;
|
int pcre2_rc;
|
||||||
|
|
||||||
@ -84,7 +87,8 @@ uint32_t *regex_replace(pcre2_code *search, char *replace, uint32_t *input, cons
|
|||||||
}
|
}
|
||||||
PCRE2_SIZE outlen = bufsize;
|
PCRE2_SIZE outlen = bufsize;
|
||||||
|
|
||||||
pcre2_rc = pcre2_substitute(search, (PCRE2_SPTR) input, input_len,
|
pcre2_rc = pcre2_substitute(search,
|
||||||
|
(PCRE2_SPTR) input, PCRE2_ZERO_TERMINATED,
|
||||||
0, /* start offset */
|
0, /* start offset */
|
||||||
options,
|
options,
|
||||||
NULL, /* ptr to a match data block */
|
NULL, /* ptr to a match data block */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user