diff options
author | Marek Olšák <[email protected]> | 2011-01-24 23:41:51 +0100 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2011-01-26 10:48:21 +0100 |
commit | c7c733545a19aab3e2b954153b9348ebe3147368 (patch) | |
tree | b0fa789271d3e16b356e6d831680911936008749 /src/gallium/auxiliary/util/u_debug.c | |
parent | 0657fc00dd9e69f71d679d480b5d5f4c33cfae35 (diff) |
util: require debug options to be separated by commas
Let's assume there are two options with names such that one is a substring
of another. Previously, if we only specified the longer one as a debug option,
the shorter one would be considered specified as well (because of strstr).
This commit fixes it by checking that each option is surrounded by commas.
(a regexp would be nicer, but this is not a performance critical code)
Diffstat (limited to 'src/gallium/auxiliary/util/u_debug.c')
-rw-r--r-- | src/gallium/auxiliary/util/u_debug.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 59b76136ad1..8cf76608e68 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -180,6 +180,43 @@ debug_get_num_option(const char *name, long dfault) return result; } +static boolean str_has_option(const char *str, const char *name) +{ + const char *substr; + + /* OPTION=all */ + if (!util_strcmp(str, "all")) { + return TRUE; + } + + /* OPTION=name */ + if (!util_strcmp(str, name)) { + return TRUE; + } + + substr = util_strstr(str, name); + + if (substr) { + unsigned name_len = strlen(name); + + /* OPTION=name,... */ + if (substr == str && substr[name_len] == ',') { + return TRUE; + } + + /* OPTION=...,name */ + if (substr+name_len == str+strlen(str) && substr[-1] == ',') { + return TRUE; + } + + /* OPTION=...,name,... */ + if (substr[-1] == ',' && substr[name_len] == ',') { + return TRUE; + } + } + + return FALSE; +} unsigned long debug_get_flags_option(const char *name, @@ -207,7 +244,7 @@ debug_get_flags_option(const char *name, else { result = 0; while( flags->name ) { - if (!util_strcmp(str, "all") || util_strstr(str, flags->name )) + if (str_has_option(str, flags->name)) result |= flags->value; ++flags; } |