From 348fff3dd435538c9e71d32497ffcc2ead86e684 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 21 Nov 2017 15:42:17 -0800 Subject: [PATCH] Catch divide-by-zero errors early in license tool (flutter/engine#4382) If Progress is instantiated with a max of 0, throw immediately to avoid a divide-by-zero later in toString(). This typically happens if the tool recurses over an empty top-level component, which can happen when a component is moved around in the repo and the developer hasn't cleaned up old empty directories from their git client. --- engine/src/flutter/tools/licenses/lib/main.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/tools/licenses/lib/main.dart b/engine/src/flutter/tools/licenses/lib/main.dart index d855b3a9153..7f4566a87fa 100644 --- a/engine/src/flutter/tools/licenses/lib/main.dart +++ b/engine/src/flutter/tools/licenses/lib/main.dart @@ -2313,7 +2313,13 @@ class RepositoryRoot extends RepositoryDirectory { class Progress { - Progress(this.max); + Progress(this.max) { + // This may happen when a git client contains left-over empty component + // directories after DEPS file changes. + if (max <= 0) + throw new ArgumentError('Progress.max must be > 0 but was: $max'); + } + final int max; int get withLicense => _withLicense; int _withLicense = 0;