Code

data: Let sdb_data_parse() support inline casts from string to other types.
authorSebastian Harl <sh@tokkee.org>
Wed, 15 Oct 2014 13:15:25 +0000 (15:15 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 15 Oct 2014 13:15:25 +0000 (15:15 +0200)
src/core/data.c
src/include/core/data.h

index 4e52133484b8e219cdef562a86a7a9991bc2279e..a796b21eef37a57c4cc422836f5386f5c11c14ba 100644 (file)
@@ -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) {
index f1c0324a1e6b7cd9d736255ec25917b3bfa2325f..ffddf979f5509593417c80d6b3358b0b75e27a34 100644 (file)
@@ -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