On Tue 17 Jun 2014 04:27:23 Dmitry V. Levin wrote: > On Sun, Jun 15, 2014 at 09:14:05AM +0530, [email protected] wrote: > > +int > > +print_tracee_cwd(struct tcb *tcp) > > ... so let's make this function static bool. > > > +{ > > + int link_size = sizeof("/proc/%u/cwd") + sizeof(int) * 3; > > sizeof("/proc//cwd") + sizeof(int) * 3 is sufficient, but I do not insist.
maybe:
const char fmt[] = "/proc/%u/cwd";
size_t link_size = sizeof(fmt) ...
...
snprintf(linkpath, link_size, fmt, ...);
i'd also highlight:
- snprintf 2nd arg is size_t, not int
- return value of snprintf really needs to be checked
- assuming sizeof(int) * 3 is large enough to hold the string representation
of a number is really bad form. sure, it works, but it's ugly as sin.
all that said, this is exactly the sort of thing asprintf() was invented. so
really we should delete all this logic and do:
char *path = asprintf("/proc/%u/cwd", tcp->pid);
if (!path)
return false;
... do stuff with path ...
free(path);
-mike
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing & Easy Data Exploration http://p.sf.net/sfu/hpccsystems
_______________________________________________ Strace-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/strace-devel
