On Montag, 3. März 2008, Bernhard Herzog wrote:
> On Monday 03 March 2008 16:06, [EMAIL PROTECTED] wrote:
> > --- trunk/openvas-libnasl/nasl/nasl_text_utils.c 2008-03-03 14:02:15 UTC
> > (rev 695)
> > +++ trunk/openvas-libnasl/nasl/nasl_text_utils.c 2008-03-03 15:06:58 UTC
> > (rev 696)
> > @@ -348,7 +348,7 @@
> > {
> > char tmp[3];
> > snprintf(tmp, sizeof(tmp), "%02x", (unsigned char)s[i]);
> > - strcat(ret, tmp);
> > + strcat(ret, tmp); /* Flawfinder: ignore */
> > }
> >
> > retc = alloc_tree_cell(0, NULL);
>
>
> In this particular case, I think it would be better to replace the loop
> with something like this:
>
> for(i=0; i<len; i++)
> {
> snprintf(ret + 2 + i, 3, "%02x", (unsigned char)s[i]);
> }
>
> This makes the code simpler, avoids strcat altogether and should be more
> efficient. The original code has quadratic runtime because the strcat has to
> repeatedly determine the length of ret.
>
> If we change the code in this way, we should add a testcase for
> hexstr to the testsuite, though.
makes sense to me. I do not expect huge performance wins. hexstr
is used only in some dozen NASL scripts and probably not in extensive
loops.
However, I'd welcome the impementation of this including the test.
Best
Jan
--
Dr. Jan-Oliver Wagner Intevation GmbH, Osnabrück
Amtsgericht Osnabrück, HR B 18998 http://www.intevation.de/
Geschäftsführer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner
_______________________________________________
Openvas-devel mailing list
[email protected]
http://lists.wald.intevation.org/mailman/listinfo/openvas-devel