<div class="gmail_quote">On Wed, Jan 26, 2011 at 12:17 PM, José Fonseca <span dir="ltr">&lt;<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>&gt;</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>
&gt; Let&#39;s assume there are two options with names such that one is a substring<br>
&gt; of another. Previously, if we only specified the longer one as a debug option,<br>
&gt; the shorter one would be considered specified as well (because of strstr).<br>
&gt; This commit fixes it by checking that each option is surrounded by commas.<br>
&gt;<br>
&gt; (a regexp would be nicer, but this is not a performance critical code)<br>
&gt; ---<br>
&gt;  src/gallium/auxiliary/util/u_debug.c |   39 +++++++++++++++++++++++++++++++++-<br>
&gt;  1 files changed, 38 insertions(+), 1 deletions(-)<br>
&gt;<br>
&gt; diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c<br>
&gt; index 59b7613..8cf7660 100644<br>
&gt; --- a/src/gallium/auxiliary/util/u_debug.c<br>
&gt; +++ b/src/gallium/auxiliary/util/u_debug.c<br>
&gt; @@ -180,6 +180,43 @@ debug_get_num_option(const char *name, long dfault)<br>
&gt;     return result;<br>
&gt;  }<br>
&gt;<br>
&gt; +static boolean str_has_option(const char *str, const char *name)<br>
&gt; +{<br>
&gt; +   const char *substr;<br>
&gt; +<br>
&gt; +   /* OPTION=all */<br>
&gt; +   if (!util_strcmp(str, &quot;all&quot;)) {<br>
&gt; +      return TRUE;<br>
&gt; +   }<br>
&gt; +<br>
&gt; +   /* OPTION=name */<br>
&gt; +   if (!util_strcmp(str, name)) {<br>
&gt; +      return TRUE;<br>
&gt; +   }<br>
&gt; +<br>
&gt; +   substr = util_strstr(str, name);<br>
&gt; +<br>
&gt; +   if (substr) {<br>
&gt; +      unsigned name_len = strlen(name);<br>
&gt; +<br>
&gt; +      /* OPTION=name,... */<br>
&gt; +      if (substr == str &amp;&amp; substr[name_len] == &#39;,&#39;) {<br>
&gt; +         return TRUE;<br>
&gt; +      }<br>
&gt; +<br>
&gt; +      /* OPTION=...,name */<br>
&gt; +      if (substr+name_len == str+strlen(str) &amp;&amp; substr[-1] == &#39;,&#39;) {<br>
&gt; +         return TRUE;<br>
&gt; +      }<br>
&gt; +<br>
&gt; +      /* OPTION=...,name,... */<br>
&gt; +      if (substr[-1] == &#39;,&#39; &amp;&amp; substr[name_len] == &#39;,&#39;) {<br>
&gt; +         return TRUE;<br>
&gt; +      }<br>
&gt; +   }<br>
&gt; +<br>
&gt; +   return FALSE;<br>
&gt; +}<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 &quot;foo&quot; in &quot;OPTION=prefixfoosuffix,foo&quot;, so<br>
it&#39;s replacing a bug with another.<br>
<br>
I&#39;d prefer we stop using strstr completely, and instead do:<br>
1 - find the first &#39;,&#39; or &#39;\0&#39; 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 &#39;,&#39; go back to 1, but starting from character after &#39;,&#39;.<br>
4 - otherwise return FALSE<br>
<br>
It should be robust and almost the same amount of code.<br></blockquote><div><br>Alright. I&#39;ll fix it.<br>
<br>
Marek<br></div></div>