lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140822152354.GB22315@krava.brq.redhat.com>
Date:	Fri, 22 Aug 2014 17:23:55 +0200
From:	Jiri Olsa <jolsa@...hat.com>
To:	Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:	Jiri Olsa <jolsa@...nel.org>, linux-kernel@...r.kernel.org,
	Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
	David Ahern <dsahern@...il.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Ingo Molnar <mingo@...nel.org>,
	Jean Pihet <jean.pihet@...aro.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Paul Mackerras <paulus@...ba.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>
Subject: Re: [PATCH 2/2] perf tools: Add +field argument support for --sort
 option

On Fri, Aug 22, 2014 at 12:16:51PM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

> >  }
> >  
> > +static int setup_sort_order(void)
> > +{
> > +#define BUF_MAX 4096
> 
> This is an arbitrary value, and you will use this just here, so you
> could just have used a number and later used sizeof(buf).
> 
> Anyway, what bothers me is the use of yet another static buffer.
> 
> The thing to use here is asprintf, that will do it all for you, format
> _and_ allocate a buffer the size you need.
> 
> > +	static char buf[BUF_MAX];
> > +
> > +	if (!sort_order || is_strict_order(sort_order))
> > +		return 0;
> > +
> > +	if (!strlen(sort_order + 1)) {
> > +		error("Invalid --fields key: `+'");
> > +		return -EINVAL;
> > +	}
> > +
> > +	scnprintf(buf, BUF_MAX, "%s,%s",
> > +		  get_default_sort_order(),
> > +		  sort_order + 1);
> > +
> > +	sort_order = buf;
> 
> I.e. it would be better to have this as:
> 
> 	char *new_sort_order;
> 
> 	if (sort_order[1] == '\0') {
> 		error("Invalid --fields key: `+'");
> 		return -EINVAL;
> 	}
> 
> 	if (asprintf(&new_sort_order, "%s,%s",
> 		     get_default_sort_order(), sort_order + 1) < 0) {
> 		error("Not enough memory to set up --sort");
> 		return -ENOMEM;
> 	}

ok, will check the asprintf

> 		
> 	sort_order = new_sort_order;
> 
> > +	return 0;
> 
> 
> Also please fix the error message, there is a cut'n'paste error there :-)

aargh right ;-)

I'll send v2

thanks,
jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ