[ofa-general] Re: [PATCH] osm: source and destination strings overlap when using sprintf()

Yevgeny Kliteynik kliteyn at dev.mellanox.co.il
Mon Apr 30 23:56:39 PDT 2007


Sasha Khapyorsky wrote:
> On 01:11 Wed 25 Apr     , Yevgeny Kliteynik wrote:
>> Michael S. Tsirkin wrote:
>>> Since you seem to do a strcat which does an anyway, how about, for example:
>>>
>>> -      sprintf( buf_line1,"%s 0x%01x |",
>>> -               buf_line1, p_vla_tbl->vl_entry[i].vl);
>>> +      sprintf( buf_line1 + strlen(buf_line1)," 0x%01x |",
>>> +               p_vla_tbl->vl_entry[i].vl);
>>>
>>> and so on in all the other places?
>> Agree.
>> I'll send a new patch later.
> 
> Or like this:
> 
> +      int n = 0;
> ...
> -      sprintf( buf_line1,"%s 0x%01x |",
> -               buf_line1, p_vla_tbl->vl_entry[i].vl);
> +      n += sprintf( buf_line1 + n," 0x%01x |",
> +                    p_vla_tbl->vl_entry[i].vl);
> 
> , so strlen() rerunning in loop is not needed anymore.

Right, it does look better.

-- Yevgeny

> Sasha
> 




More information about the general mailing list