diff options
Diffstat (limited to 'src/sp_config_utils.c')
| -rw-r--r-- | src/sp_config_utils.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c index 130f07e..d72561b 100644 --- a/src/sp_config_utils.c +++ b/src/sp_config_utils.c | |||
| @@ -32,18 +32,18 @@ int parse_keywords(sp_config_functions *funcs, char *line) { | |||
| 32 | return 0; | 32 | return 0; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | char *get_param(size_t *consumed, char *restrict line, sp_type type, | 35 | zend_string *get_param(size_t *consumed, char *restrict line, sp_type type, |
| 36 | const char *restrict keyword) { | 36 | const char *restrict keyword) { |
| 37 | enum { IN_ESCAPE, NONE } state = NONE; | 37 | enum { IN_ESCAPE, NONE } state = NONE; |
| 38 | char *original_line = line; | 38 | char *original_line = line; |
| 39 | size_t j = 0; | 39 | size_t j = 0; |
| 40 | 40 | ||
| 41 | char *ret = NULL; | 41 | zend_string *ret = NULL; |
| 42 | if (NULL == line || '\0' == *line) { | 42 | if (NULL == line || '\0' == *line) { |
| 43 | goto err; | 43 | goto err; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | ret = pecalloc(sizeof(char), strlen(original_line) + 1, 1); | 46 | ret = zend_string_alloc(strlen(line) + 1, 1); |
| 47 | 47 | ||
| 48 | /* The first char of a string is always '"', since they MUST be quoted. */ | 48 | /* The first char of a string is always '"', since they MUST be quoted. */ |
| 49 | if ('"' == *line) { | 49 | if ('"' == *line) { |
| @@ -65,6 +65,11 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type, | |||
| 65 | 2. the SP_TOKEN_END_PARAM | 65 | 2. the SP_TOKEN_END_PARAM |
| 66 | */ | 66 | */ |
| 67 | *consumed = i + 2; | 67 | *consumed = i + 2; |
| 68 | // Make sure that the string we return is the right size, | ||
| 69 | // as it can be smaller than strlen(line) | ||
| 70 | ret = zend_string_truncate(ret, j, 1); | ||
| 71 | // truncate does not add a \0 | ||
| 72 | ZSTR_VAL(ret)[ZSTR_LEN(ret)] = 0; | ||
| 68 | return ret; | 73 | return ret; |
| 69 | } else if (state == IN_ESCAPE) { | 74 | } else if (state == IN_ESCAPE) { |
| 70 | break; // we're on an escped double quote | 75 | break; // we're on an escped double quote |
| @@ -82,7 +87,7 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type, | |||
| 82 | if (state == IN_ESCAPE) { | 87 | if (state == IN_ESCAPE) { |
| 83 | state = NONE; | 88 | state = NONE; |
| 84 | } | 89 | } |
| 85 | ret[j++] = line[i]; | 90 | ZSTR_VAL(ret)[j++] = line[i]; |
| 86 | } | 91 | } |
| 87 | err: | 92 | err: |
| 88 | if (0 == j) { | 93 | if (0 == j) { |
