<div class="gmail_quote">On Wed, Jan 26, 2011 at 12:17 PM, José Fonseca <span dir="ltr"><<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On Mon, 2011-01-24 at 20:52 -0800, Marek Olšák wrote:<br>
> Let's assume there are two options with names such that one is a substring<br>
> of another. Previously, if we only specified the longer one as a debug option,<br>
> the shorter one would be considered specified as well (because of strstr).<br>
> This commit fixes it by checking that each option is surrounded by commas.<br>
><br>
> (a regexp would be nicer, but this is not a performance critical code)<br>
> ---<br>
> src/gallium/auxiliary/util/u_debug.c | 39 +++++++++++++++++++++++++++++++++-<br>
> 1 files changed, 38 insertions(+), 1 deletions(-)<br>
><br>
> diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c<br>
> index 59b7613..8cf7660 100644<br>
> --- a/src/gallium/auxiliary/util/u_debug.c<br>
> +++ b/src/gallium/auxiliary/util/u_debug.c<br>
> @@ -180,6 +180,43 @@ debug_get_num_option(const char *name, long dfault)<br>
> return result;<br>
> }<br>
><br>
> +static boolean str_has_option(const char *str, const char *name)<br>
> +{<br>
> + const char *substr;<br>
> +<br>
> + /* OPTION=all */<br>
> + if (!util_strcmp(str, "all")) {<br>
> + return TRUE;<br>
> + }<br>
> +<br>
> + /* OPTION=name */<br>
> + if (!util_strcmp(str, name)) {<br>
> + return TRUE;<br>
> + }<br>
> +<br>
> + substr = util_strstr(str, name);<br>
> +<br>
> + if (substr) {<br>
> + unsigned name_len = strlen(name);<br>
> +<br>
> + /* OPTION=name,... */<br>
> + if (substr == str && substr[name_len] == ',') {<br>
> + return TRUE;<br>
> + }<br>
> +<br>
> + /* OPTION=...,name */<br>
> + if (substr+name_len == str+strlen(str) && substr[-1] == ',') {<br>
> + return TRUE;<br>
> + }<br>
> +<br>
> + /* OPTION=...,name,... */<br>
> + if (substr[-1] == ',' && substr[name_len] == ',') {<br>
> + return TRUE;<br>
> + }<br>
> + }<br>
> +<br>
> + return FALSE;<br>
> +}<br>
<br>
</div></div>Marek,<br>
<br>
The intention is good -- it would be nice to get options obeyed properly<br>
--, but this will fail to find "foo" in "OPTION=prefixfoosuffix,foo", so<br>
it's replacing a bug with another.<br>
<br>
I'd prefer we stop using strstr completely, and instead do:<br>
1 - find the first ',' or '\0' in the string<br>
2 - compare the previous characters with the option being searched, and<br>
return TRUE if matches<br>
3 - if it was ',' go back to 1, but starting from character after ','.<br>
4 - otherwise return FALSE<br>
<br>
It should be robust and almost the same amount of code.<br></blockquote><div><br>Alright. I'll fix it.<br>
<br>
Marek<br></div></div>