[ofa-general] Re: [PATCH] osm: source and destination strings overlap when using sprintf()
Sasha Khapyorsky
sashak at voltaire.com
Mon Apr 30 17:51:01 PDT 2007
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.
Sasha
More information about the general
mailing list