From: Lucian Poston Date: Mon, 16 Apr 2012 11:04:38 GMT Subject: Re: [PATCH v2 2/3] Adjust stat width calculations to take --graph output into account Message-ID: In-Reply-To: <4F86ABA7.8080703@in.waw.pl> On Thu, Apr 12, 2012 at 03:17, Zbigniew Jędrzejewski-Szmek wrote: >>>> + >>>> +             /* >>>> +              * If the remaining unreserved space will not accomodate >>>> the >>>> +              * filenames, adjust name_width to use all available >>>> remaining space. >>>> +              * Otherwise, assign any extra space to graph_width. >>>> +              */ >>>> +             if (name_width>    width - reserved_character_count - >>>> graph_width) { >>>> +                     name_width = width - reserved_character_count - >>>> graph_width; >>>> +             } else { >>>> +                     graph_width = width - reserved_character_count - >>>> name_width; >>>> +             } >>>> + >>>> +             /* >>>> +              * If stat-graph-width was specified, limit graph_width to >>>> its value. >>>> +              */ >>>>               if (options->stat_graph_width&& >>>> -                 graph_width>    options->stat_graph_width) >>>> +                             graph_width>    options->stat_graph_width) >>>> { >>>>                       graph_width = options->stat_graph_width; >>>> -             if (name_width>    width - number_width - 6 - graph_width) >>>> -                     name_width = width - number_width - 6 - >>>> graph_width; >>>> -             else >>>> -                     graph_width = width - number_width - 6 - >>>> name_width; >>>> +             } >>> >>> Here, the order of the two tests >>> (1) if (options->stat_graph_width&&  graph_width> >>>  options->stat_graph_width) >>> >>> (2) if (name_width>  width - number_width - 6 - graph_width) >>> is reversed. This is not OK, because this means that >>> options->stat_graph_width will be used unconditionally, while >>> before it was subject to limiting by total width. >> >> >> If options->stat_graph_width is specified, it should always limit the >> value of graph_width, correct? Since (1) is the last test, it can only >> decrease the value of graph_width, which would already be limited by >> the total width. > > Right, but the way the tests are ordered now, we could end up decreasing > name_width first (after (2)) and then graph_width (after (1)), actually > using less than full width. Ahh, I didn't think about that. I just reverted the order back to the original. >> I just noticed that name_width isn't being limited to stat_name_width, >> if it is specified. I'll add a check for that. > > Sounds good. FYI, in patch v3, I reverted the check for stat_graph_width as previously mentioned, and I ended up not adding a check for stat_name_width. It remains the case that in certain scenarios, name_width & graph_width could be set to values greater than stat_name_width & stat_graph_width.