On Mon, Jun 16, 2014 at 10:29:48PM -0400, Mike Frysinger wrote:
> 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

Being pedantic, I'd also make it const.

>  - return value of snprintf really needs to be checked

In general, yes, but current practice is not to check for "cannot happen"
events.

>  - 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.

If it surely works and easy to read, then it is acceptable.

> all that said, this is exactly the sort of thing asprintf() was invented.  so 

I think asprintf is for arbitrary (or just too big) sizes.  In cases
like this (when buffer of 21 bytes is surely enough) I'd rather use stack.


-- 
ldv

Attachment: pgpaZ3DrlaN12.pgp
Description: PGP signature

------------------------------------------------------------------------------
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

Reply via email to