This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 25590 - Off-by-one in 3.2.6 effective overload set algorithm
Summary: Off-by-one in 3.2.6 effective overload set algorithm
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-07 17:06 UTC by Joshua Bell
Modified: 2017-07-30 13:24 UTC (History)
4 users (show)

See Also:


Attachments

Description Joshua Bell 2014-05-07 17:06:09 UTC
In the "how to compute an effective overload set" algorithm:

7. While i ≥ 0:
   1. If argument i of X is not optional, then break this loop.
   2. Otherwise, add to S the tuple <X, t0..i−1, o0..i−1>.
   3. Set i to i−1.
8. If n > 0 and all arguments of X are optional, then add to S the tuple <X, (), ()> (where “()” represents the empty list).

In the loop at step (7), if i == 0, then in (7.2) either the syntax  <X, t0..i-1, o0..i-1> is referencing negative indexes *or* this is adding <X, (), ()> to S, which is redundant with step (8).

I believe this was introduced in:

https://github.com/heycam/webidl/commit/97499d48855a9f9012fe145d49b83ccd71d1738b#diff-1feda49b40370635faef8b655f144f64L3228

... where the previous version required 0 < i < n.
Comment 1 Nils Barth 2014-05-08 05:36:20 UTC
Thanks Joshua!
I'm referring to:
http://heycam.github.io/webidl/#dfn-effective-overload-set

To fix this, there are two solutions, right?

Option A:
Replace:
7. While i ≥ 0:
with:
7. While i > 0:

Option B:
Remove: 8. If n > 0 ...
...and preferably amend 5.7.2 to:
2. Otherwise, add to S the tuple <X, t0..i−1, o0..i−1>; if i is 0, this means to add to S the tuple <X, (), ()> (where “()” represents the empty list).


Option A is probably simpler and more explicit spec-wise, because it avoids the negative indexes and is explicit about the bound.
Comment 2 Joshua Bell 2014-05-08 16:11:03 UTC
(In reply to Nils Barth from comment #1)
> To fix this, there are two solutions, right?

Yep, and I agree that A seems simpler.

We might be missing some intentional subtlety, though, so I just wanted to point out the issue and let Cameron weigh in.
Comment 3 Tobie Langel 2017-07-28 14:00:03 UTC
Tentative fix: https://github.com/heycam/webidl/pull/390
Comment 4 Tobie Langel 2017-07-30 13:24:03 UTC
Fixed in https://github.com/heycam/webidl/commit/fb40c8e