lib/conf.c: strip whitespace after value in config
Closes: #407 [via git-merge-pr]
This commit is contained in:
parent
18416e2de8
commit
453595a822
12
lib/conf.c
12
lib/conf.c
@ -196,7 +196,7 @@ static const struct key {
|
|||||||
static int
|
static int
|
||||||
parse_option(char *buf, const char **keyp, char **valp)
|
parse_option(char *buf, const char **keyp, char **valp)
|
||||||
{
|
{
|
||||||
size_t klen;
|
size_t klen, end;
|
||||||
const char *key;
|
const char *key;
|
||||||
char *value;
|
char *value;
|
||||||
int k = 0;
|
int k = 0;
|
||||||
@ -224,8 +224,14 @@ parse_option(char *buf, const char **keyp, char **valp)
|
|||||||
while (isblank((unsigned char)*value))
|
while (isblank((unsigned char)*value))
|
||||||
value++;
|
value++;
|
||||||
|
|
||||||
/* eat final newline */
|
end = strlen(value);
|
||||||
value[strlen(value)-1] = '\0';
|
/* eat trailing spaces, end - 1 here because \0 should be set -after- the first non-space
|
||||||
|
* if end points at the actual current character, we can never make it an empty string
|
||||||
|
* because than end needs to be set to -1, but end is a unsigned type thus would result in underflow */
|
||||||
|
while (end > 0 && isspace((unsigned char)value[end - 1]))
|
||||||
|
end--;
|
||||||
|
|
||||||
|
value[end] = '\0';
|
||||||
|
|
||||||
/* option processed successfully */
|
/* option processed successfully */
|
||||||
*keyp = key;
|
*keyp = key;
|
||||||
|
Loading…
Reference in New Issue
Block a user