Created
April 1, 2016 16:04
-
-
Save psychon/ce61abbab5039b8b99667b24f3fe93fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Makefile.am b/Makefile.am | |
index 456e9c2..62b528b 100644 | |
--- a/Makefile.am | |
+++ b/Makefile.am | |
@@ -31,6 +31,7 @@ libxcb_xrm_la_LDFLAGS = -version-info 0:0:0 -no-undefined -export-symbols-regex | |
pkgconfig_DATA = xcb-xrm.pc | |
+AM_TESTS_ENVIRONMENT = HOME=$(srcdir)/tests/ XENVIRONMENT=$(srcdir)/tests/Xenv | |
TESTS = tests/test | |
check_PROGRAMS = tests/test | |
tests_test_SOURCE = tests/test.c | |
diff --git a/include/xcb_xrm.h b/include/xcb_xrm.h | |
index 51d6b54..7ef126a 100644 | |
--- a/include/xcb_xrm.h | |
+++ b/include/xcb_xrm.h | |
@@ -162,6 +162,8 @@ char *xcb_xrm_database_to_string(xcb_xrm_database_t *database); | |
* overridden if override is set; otherwise, the value is discarded. | |
* The source database will implicitly be free'd and must not be used | |
* afterwards. | |
+ * That's a pity. Wouldn't it be more useful to keep the source_db alive? That | |
+ * might make it easier to track the life time of databases. | |
* If NULL is passed for target_db, a new and empty database will be created | |
* and returned in the pointer. | |
* | |
diff --git a/src/database.c b/src/database.c | |
index 54ad245..2492d22 100644 | |
--- a/src/database.c | |
+++ b/src/database.c | |
@@ -230,7 +230,7 @@ xcb_xrm_database_t *xcb_xrm_database_from_string(const char *_str) { | |
} | |
filename = &line[i]; | |
- line[j+i] = '\0'; | |
+ line[j+1] = '\0'; | |
included = xcb_xrm_database_from_file(filename); | |
@@ -392,7 +392,7 @@ void xcb_xrm_database_put_resource_line(xcb_xrm_database_t **database, const cha | |
if (xcb_xrm_entry_parse(line, &entry, false) == 0) { | |
xcb_xrm_database_put(*database, entry, true); | |
} else { | |
- xcb_xrm_entry_free(entry); | |
+ xcb_xrm_entry_free(entry); /* XXX: This is a double-free, I think */ | |
} | |
} | |
diff --git a/src/entry.c b/src/entry.c | |
index 720d50e..9bf32dc 100644 | |
--- a/src/entry.c | |
+++ b/src/entry.c | |
@@ -192,6 +192,9 @@ int xcb_xrm_entry_parse(const char *_str, xcb_xrm_entry_t **_entry, bool resourc | |
goto process_normally; | |
case ':': | |
if (resource_only) { | |
+ /* This suggests that this should be split into two parsers, | |
+ * one resource_only, one for the value | |
+ */ | |
goto done_error; | |
} | |
diff --git a/src/match.c b/src/match.c | |
index 4a0ad1c..f8ff956 100644 | |
--- a/src/match.c | |
+++ b/src/match.c | |
@@ -42,6 +42,8 @@ static void __match_free(xcb_xrm_match_t *match); | |
* Finds the matching entry in the database given a full name / class query string. | |
* | |
*/ | |
+/* Prefix this (and all other non-static functions that should not be exported) | |
+ * with an underscore */ | |
int xcb_xrm_match(xcb_xrm_database_t *database, xcb_xrm_entry_t *query_name, xcb_xrm_entry_t *query_class, | |
xcb_xrm_resource_t *resource) { | |
xcb_xrm_match_t *best_match = NULL; | |
@@ -151,6 +153,7 @@ static int __match_matches(xcb_xrm_entry_t *db_entry, xcb_xrm_entry_t *query_nam | |
break; | |
default: | |
/* Never reached. */ | |
+ assert(0); | |
return -FAILURE; | |
} | |
} | |
diff --git a/tests/test.c b/tests/test.c | |
index 2f5a6d3..b3af263 100644 | |
--- a/tests/test.c | |
+++ b/tests/test.c | |
@@ -58,6 +58,7 @@ static int test_get_resource(void); | |
static int test_put_resource(void); | |
static int test_combine_databases(void); | |
static int test_convert(void); | |
+static int test_read_file(void); | |
/* Assertion utilities */ | |
static bool check_strings(const char *expected, const char *actual, | |
@@ -86,6 +87,7 @@ int main(void) { | |
err |= test_put_resource(); | |
err |= test_combine_databases(); | |
err |= test_convert(); | |
+ err |= test_read_file(); | |
cleanup(); | |
return err; | |
@@ -417,6 +419,15 @@ static int test_convert(void) { | |
return err; | |
} | |
+static int test_read_file(void) { | |
+ int err = 0; | |
+ xcb_xrm_database_t *db = xcb_xrm_database_from_default(conn); | |
+ | |
+ xcb_xrm_database_free(db); | |
+ | |
+ return err; | |
+} | |
+ | |
static bool check_strings(const char *expected, const char *actual, | |
const char *format, ...) { | |
va_list ap; | |
@@ -474,6 +485,8 @@ static void setup(void) { | |
exit(EXIT_FAILURE); | |
} | |
+ //xcb_xrm_database_t *db = xcb_xrm_database_from_default(conn); | |
+ | |
XrmInitialize(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment