Debian Codegraph @

basic/qa/basic_coverage/test_string_overflow_safe.bas

raw
1 ' This file is part of the LibreOffice project.
2 '
3 ' This Source Code Form is subject to the terms of the Mozilla Public
4 ' License, v. 2.0. If a copy of the MPL was not distributed with this
5 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 '
7
8 Option Explicit
9
10 Function doUnitTest As String
11 ' Trying to create too long string should generate proper BASIC overflow error.
12 ' Longest possible string is 2147483638 wchar_t (2G - 10).
13 ' This tries to create string with 2G wchar_t. If it does not overflow, test fails.
14 ' If overflow is not safe, it segfaults.
15 On Error GoTo errorHandler
16 Dim s As String, i As Integer
17 s = "0"
18 For i=1 To 31
19 s = s & s
20 Next i
21 doUnitTest = "FAIL"
22 Exit Function
23 errorHandler:
24 If ( Err <> 6 ) Then
25 doUnitTest = "FAIL"
26 Else
27 doUnitTest = "OK"
28 Endif
29 End Function