Skip to content

Commit

Permalink
BitStack::top() should calculate an index instead of always using m_w…
Browse files Browse the repository at this point in the history
…ords.last()

BitStack::top() should calculate an index instead of always using m_words.last()
https://bugs.webkit.org/show_bug.cgi?id=142224

Reviewed by Antti Koivisto.

Merge - https://chromium.googlesource.com/chromium/blink/+/6513eab4e0dae0ff8556dd6ddbbb9c475bec2d32

This patch is to fix a logical error, where if the stack gets deeper than sizeof(unsigned),
the result reported by top() can be incorrect if anything has been popped.

* Source/WebCore/editing/TextIterator.cpp:
(BitStack::top): Add unsigned variable "index" and use it as an array for return value

Canonical link: https://commits.webkit.org/258190@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Dec 21, 2022
1 parent 01e7ec3 commit 409456b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/WebCore/editing/TextIterator.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2004-2020 Apple Inc. All rights reserved.
* Copyright (C) 2004-2022 Apple Inc. All rights reserved.
* Copyright (C) 2015 Google Inc. All rights reserved.
* Copyright (C) 2005 Alexey Proskuryakov.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -174,7 +175,8 @@ bool BitStack::top() const
if (!m_size)
return false;
unsigned shift = (m_size - 1) & bitInWordMask;
return m_words.last() & (1U << shift);
unsigned index = (m_size - 1) / bitsInWord;
return m_words[index] & (1U << shift);
}

// --------
Expand Down

0 comments on commit 409456b

Please sign in to comment.