infinite loop in 'partition' and 'partition-all' when 'step' or 'n' is not positive

Description

If you pass a non-positive value of 'n' or 'step' to partition, you get an infinite loop. Here are a few examples:

(partition 0 [1 2 3])
(partition 1 -1 [1 2 3])

Cause: partition and partition-all do not check that n and step are positive.

Approach: Add checks to partition and partition-all that n and step are positive. To avoid redoing the arg validation, factored out internals of partition and partition-all to private internal-partition and internal-partition-all.

Patch: clj-1647_3.patch

Screened by: Alex Miller

Environment

None

Activity

Show:
Kevin Woram
July 27, 2015, 6:10 PM

Thanks for solving that mystery Matthew!

Alex Miller
March 10, 2016, 8:45 PM

Patch looks basically good. Minor changes:

  • internal-partition and internal-partition-all should be marked private with defn-.

  • Commit description should start with "CLJ-1647"

Matthew Gilliard
April 26, 2016, 4:32 PM

I added clj-1647_2.patch to supersede other patches on this issue. Jira ref is added to commit msg and defn- used where possible (defn- is not defined until after one of the private fns but there is the ^rivate metadata added manually)

Alex Miller
April 26, 2016, 5:42 PM

The patch changes add-annotation from defn- to defn but that seems unrelated to the intent of the patch?

Matthew Gilliard
April 27, 2016, 9:15 AM

Thanks for looking so quickly Alex - sorry about that error in add-annotation. See clj-1647_3.patch

Assignee

Unassigned

Reporter

Kevin Woram

Labels

Approval

Screened

Patch

Code and Test

Fix versions

Affects versions

Priority

Minor
Configure