Don't use strcat
and tmp
. You're writing senselessly overcomplicated and inefficient code. Instead:
pos+=sprintf(pos,"%f ",cl.snap.ps.origin[0]);
pos+=sprintf(pos,"%f ",cl.snap.ps.origin[1]);
...
Unless you're sure sprintf
cannot fail, rather than directly adding the return value to pos
, you should probably first store the return value in a separate int
variable and check that it's not -1.
It would also be better to use snprintf
to make sure you don't overflow your buffer:
size_t cnt, rem=your_buffer_size;
cnt=snprintf(pos, rem,"%f ",cl.snap.ps.origin[0]);
if (cnt>=rem) goto error;
pos+=cnt; rem-=cnt;
cnt=snprintf(pos, rem,"%f ",cl.snap.ps.origin[1]);
if (cnt>=rem) goto error;
pos+=cnt; rem-=cnt;
...
Note that cnt
being an unsigned type (size_t
) is critical to the error check working.