From 47f31649186ace5c6cfe6742647dbb710c0f58e8 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Wed, 15 Oct 2014 15:15:25 +0200 Subject: [PATCH] data: Let sdb_data_parse() support inline casts from string to other types. --- src/core/data.c | 4 ++-- src/include/core/data.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/data.c b/src/core/data.c index 4e52133..a796b21 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -600,11 +600,11 @@ sdb_data_parse(char *str, int type, sdb_data_t *data) tmp.data.re.raw = strdup(str); if (! tmp.data.re.raw) return -1; - if (regcomp(&tmp.data.re.regex, str, + if (regcomp(&tmp.data.re.regex, tmp.data.re.raw, REG_EXTENDED | REG_ICASE | REG_NOSUB)) { free(tmp.data.re.raw); sdb_log(SDB_LOG_ERR, "core: Failed to compile regular " - "expression '%s'", str); + "expression '%s'", tmp.data.re.raw); return -1; } if (! data) { diff --git a/src/include/core/data.h b/src/include/core/data.h index f1c0324..ffddf97 100644 --- a/src/include/core/data.h +++ b/src/include/core/data.h @@ -239,6 +239,11 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted); * memory and also compiled to a regex. Use sdb_data_free_datum() to free the * dynamically allocated memory. * + * The input string may be stored in 'data', that is, the function may be used + * to do an inline cast from a string to any other type. It is the callers + * responsibility to free the memory used by the string in case the target + * type does not keep a reference to it. + * * Returns: * - 0 on success * - a negative value else -- 2.30.2