show_stats(): fix stats width calculation
Before this patch, name_width becomes negative or null for width values less than 15 and name_width values greater than 25 (default: 50). This leads to output random data. This patch checks for minimal width and name_width values. Signed-off-by: Olivier Marin <dkr@freesurf.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Olivier Marin committed
Jun 27, 2008 at 02:18 UTC
861d1af36ae168353fc352126c0bf2d189c2324a
1 file changed
+6
-6
diff.c
+6
-6
@@ -830,12 +830,12 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
830
/* Sanity: give at least 5 columns to the graph,
831
* but leave at least 10 columns for the name.
832
*/
833
- if (width < name_width + 15) {
834
- if (name_width <= 25)
835
- width = name_width + 15;
836
- else
837
- name_width = width - 15;
838
- }
833
+ if (width < 25)
834
+ width = 25;
835
+ if (name_width < 10)
836
+ name_width = 10;
837
+ else if (width < name_width + 15)
838
+ name_width = width - 15;
839
840
/* Find the longest filename and max number of changes */
841
reset = diff_get_color_opt(options, DIFF_RESET);