master - cleanup: simplify pv name size estimation
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0499e87ace39997c64b33d27a65011b1b3c6cecc Commit: 0499e87ace39997c64b33d27a65011b1b3c6cecc Parent: 3fda296da6b992dbafeaeabeacd47fe41f78221e Author: Zdenek Kabelac <[email protected]> AuthorDate: Wed Mar 26 14:00:51 2014 +0100 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Wed Mar 26 14:11:37 2014 +0100
cleanup: simplify pv name size estimation
Reuse buffer with size of 2 * PATH_MAX to handle worst case escape and avoid extra calculation of espaced len.
--- lib/format_text/export.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)
lib/format_text/export.c +4 -6
@@ -450,8 +450,7 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg) {struct pv_list *pvl;struct physical_volume *pv; -char buffer[4096 ]; -char *buf; +char buffer[PATH_MAX *2 ];const char *name;outf (f,"physical_volumes {" );
@@ -472,14 +471,13 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg)outf (f,"id = \"%s\"" , buffer); -if (!(buf =alloca (dm_escaped_len (pv_dev_name (pv))))) { -log_error ("temporary stack allocation for device name" -"string failed" ); +if (strlen (pv_dev_name (pv)) >=PATH_MAX ) { +log_error ("pv device name size is out of bounds." );return 0 ; }outhint (f,"device = \"%s\"" , -dm_escape_double_quotes (buf,pv_dev_name (pv))); +dm_escape_double_quotes (buffer,pv_dev_name (pv)));outnl (f);if (!_print_flag_config (f, pv->status,PV_FLAGS ))