Closed Bug 690132 Opened 13 years ago Closed 13 years ago

ArrayObject::try_splice assumes deletedItems array has no holes

Categories

(Tamarin Graveyard :: Library, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: pnkfelix, Assigned: pnkfelix)

References

Details

(Whiteboard: has-patch)

Attachments

(1 file)

This bit of code in ArrayObject::try_splice has a subtle bug:

  ArrayObject* deletedItems = toplevel()->arrayClass()->newArray(0);
  deletedItems->m_denseArray.splice(0, deleteCount, 0,
                                    this->m_denseArray, insertPoint);
  deletedItems->m_denseStart = 0;
  deletedItems->m_denseUsed = deleteCount;
  deletedItems->m_length = deleteCount;


The bug is that it is setting m_denseUsed to deleteCount.  But the deleteCount may be an over-estimate of the actual number of used elements in the deletedItems, because the m_denseArray may contain "holes" (i.e. atomNotFound).

At the moment, this probably only means that the dense/sparse policy decisions may be misinformed.  But a bug like this also makes it hard for me to do experiments like Bug 689828, because I am trying to confirm that my instrumentation is valid by check-summing against state like this.
Assignee: nobody → fklockii
I'm not worried about the overhead of invoking calcDenseUsed(), because we also use that same method to fix up this->m_denseUsed a few lines down.
Attachment #563206 - Flags: review?(lhansen)
Whiteboard: has-patch
Status: NEW → ASSIGNED
Comment on attachment 563206 [details] [diff] [review]
patch A: trivial fix

I think you're probably right not to worry about that cost.

That said, I think it is the case that if "this" is simple by the current definition (it is dense with a start at zero and denseUsed == length) then the number of extracted elements is equal to deleteCount.  Even if that invariant is not useful here & now it may be useful by and by.
Attachment #563206 - Flags: review?(lhansen) → review+
changeset: 6608:dfa5e5cfe076
user:      Felix S Klock II <fklockii@adobe.com>
summary:   Bug 690132: try_splice deleteItems can have holes (r=lhansen).

http://hg.mozilla.org/tamarin-redux/rev/dfa5e5cfe076
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Blocks: 690498
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: