[PATCH] Implement CONFIG_KEY_UNSIGNED_INTEGER since strtol() does not work when trying to assign 32 bits of data into a regular signed int on 32 bit systems. Use corresponding strtoul() instead.
Scott Moreau
oreaus at gmail.com
Fri Jan 27 12:25:49 PST 2012
---
clients/desktop-shell.c | 4 ++--
shared/config-parser.c | 10 ++++++++++
shared/config-parser.h | 1 +
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 4848449..3d5119a 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -107,8 +107,8 @@ static int key_locking = 1;
static const struct config_key shell_config_keys[] = {
{ "background-image", CONFIG_KEY_STRING, &key_background_image },
{ "background-type", CONFIG_KEY_STRING, &key_background_type },
- { "panel-color", CONFIG_KEY_INTEGER, &key_panel_color },
- { "background-color", CONFIG_KEY_INTEGER, &key_background_color },
+ { "panel-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_panel_color },
+ { "background-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_background_color },
{ "locking", CONFIG_KEY_BOOLEAN, &key_locking },
};
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 3b8c5c2..3d94117 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -32,6 +32,7 @@ handle_key(const struct config_key *key, const char *value)
{
char *end, *s;
int i, len;
+ unsigned int ui;
switch (key->type) {
case CONFIG_KEY_INTEGER:
@@ -43,6 +44,15 @@ handle_key(const struct config_key *key, const char *value)
*(int *)key->data = i;
return 0;
+ case CONFIG_KEY_UNSIGNED_INTEGER:
+ ui = strtoul(value, &end, 0);
+ if (*end != '\n') {
+ fprintf(stderr, "invalid integer: %s\n", value);
+ return -1;
+ }
+ *(int *)key->data = ui;
+ return 0;
+
case CONFIG_KEY_STRING:
len = strlen(value);
s = malloc(len);
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 34f5c31..a83aa4c 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -25,6 +25,7 @@
enum config_key_type {
CONFIG_KEY_INTEGER, /* typeof data = int */
+ CONFIG_KEY_UNSIGNED_INTEGER, /* typeof data = int */
CONFIG_KEY_STRING, /* typeof data = char* */
CONFIG_KEY_BOOLEAN /* typeof data = int */
};
--
1.7.4.1
More information about the wayland-devel
mailing list