| 1777 | float left; |
| 1778 | int style = ST_LEFT; |
| 1779 | if ((_style & ST_TYPE) == ST_MULTI || _firstVisible == 0) |
| 1780 | { |
| 1781 | style = _style & ST_HPOS; |
| 1782 | } |
| 1783 | float size = _scale * _size; |
| 1784 | switch (style) |
| 1785 | { |
| 1786 | case ST_RIGHT: |
| 1787 | left = _x + _w - GLOB_ENGINE->GetTextWidth(size, _font, text) - _scale * textBorder; |
| 1788 | break; |
| 1789 | case ST_CENTER: |
| 1790 | left = _x + 0.5 * (_w - GLOB_ENGINE->GetTextWidth(size, _font, text)); |
| 1791 | break; |
| 1792 | default: |
| 1793 | PoseidonAssert((_style & ST_HPOS) == ST_LEFT) left = _x + _scale * textBorder; |
| 1794 | break; |
| 1795 | } |
| 1796 | |
| 1797 | RString str = text.Substring(0, pos); |
| 1798 | return left + GLOB_ENGINE->GetTextWidth(size, _font, str); |
| 1799 | } |
| 1800 | |
| 1801 | int CEdit::XToPos(RString text, float x) const |
| 1802 | { |
| 1803 | float left; |
| 1804 | int style = ST_LEFT; |
| 1805 | if ((_style & ST_TYPE) == ST_MULTI || _firstVisible == 0) |
| 1806 | { |
| 1807 | style = _style & ST_HPOS; |
| 1808 | } |
| 1809 | float size = _scale * _size; |
| 1810 | switch (style) |
| 1811 | { |
| 1812 | case ST_RIGHT: |
| 1813 | left = _x + _w - GLOB_ENGINE->GetTextWidth(size, _font, text) - _scale * textBorder; |
| 1814 | break; |
| 1815 | case ST_CENTER: |
| 1816 | left = _x + 0.5 * (_w - GLOB_ENGINE->GetTextWidth(size, _font, text)); |
| 1817 | break; |
| 1818 | default: |
| 1819 | PoseidonAssert((_style & ST_HPOS) == ST_LEFT) left = _x + _scale * textBorder; |
| 1820 | break; |
| 1821 | } |
| 1822 | |
| 1823 | if (x < left) |
| 1824 | { |
| 1825 | return 0; |
| 1826 | } |
| 1827 | |
| 1828 | // Iterate the passed-in `text` (a single line / scrolled substring), NOT the |
| 1829 | // whole `_text`: callers pass GetLine() or a Substring shorter than _text, so |
| 1830 | // bounding the loop by strlen(_text) walks CopyTextElement past the buffer — |
| 1831 | // an out-of-bounds read (crash) or a stall at the NUL (freeze). |
| 1832 | int n = strlen(text); |
| 1833 | for (int i = 0; i < n;) |
| 1834 | { |
| 1835 | int j = i; |
nothing calls this directly
no test coverage detected