# HG changeset patch # User zas_ # Date 1211398638 0 # Node ID 9a6a7e95467a16b530d9bd8b4b9b19701645dc3a # Parent 5042236af960e6ec85450c3e0177eeebb0c934c1 Make stricter match for option's names consisting of a prefix and a number. It allows to have names like "prefix_12" and "prefix_something" in the same file. Using strtol() was wrong since it allowed names like "prefix_-0xa", leading to unpredictable results. It was wrong too with "prefix_something", which was equivalent to "prefix_0", instead of being an option of its own. diff -r 5042236af960 -r 9a6a7e95467a src/rcfile.c --- a/src/rcfile.c Wed May 21 11:46:19 2008 +0000 +++ b/src/rcfile.c Wed May 21 19:37:18 2008 +0000 @@ -595,6 +595,23 @@ *----------------------------------------------------------------------------- */ +static gboolean is_numbered_option(const gchar *option, const gchar *prefix, gint *number) +{ + gsize n; + gsize option_len = strlen(option); + gsize prefix_len = strlen(prefix); + + if (option_len <= prefix_len) return FALSE; + if (g_ascii_strncasecmp(option, prefix, prefix_len) != 0) return FALSE; + + n = prefix_len; + while (g_ascii_isdigit(option[n])) n++; + if (n < option_len) return FALSE; + + if (number) *number = atoi(option + prefix_len); + return TRUE; +} + void load_options(void) { FILE *f; @@ -839,20 +856,21 @@ READ_BOOL(color_profile.use_image); READ_INT(color_profile.input_type); - if (g_ascii_strncasecmp(option, "color_profile.input_file_", 25) == 0) + if (is_numbered_option(option, "color_profile.input_file_", &i)) { - i = strtol(option + 25, NULL, 0) - 1; - if (i >= 0 && i < COLOR_PROFILE_INPUTS) + if (i > 0 && i <= COLOR_PROFILE_INPUTS) { + i--; read_char_option(f, option, option, value, &options->color_profile.input_file[i]); } continue; } - if (g_ascii_strncasecmp(option, "color_profile.input_name_", 25) == 0) + + if (is_numbered_option(option, "color_profile.input_name_", &i)) { - i = strtol(option + 25, NULL, 0) - 1; - if (i >= 0 && i < COLOR_PROFILE_INPUTS) + if (i > 0 && i <= COLOR_PROFILE_INPUTS) { + i--; read_char_option(f, option, option, value, &options->color_profile.input_name[i]); } continue; @@ -863,9 +881,8 @@ /* External Programs */ - if (g_ascii_strncasecmp(option, "external_", 9) == 0) + if (is_numbered_option(option, "external_", &i)) { - i = strtol(option + 9, NULL, 0); if (i > 0 && i <= GQ_EDITOR_SLOTS) { const gchar *ptr;