Skip to content

Commit a6ca278

Browse files
committed
bugfix: sf.net #794 literal tabs in string literals miscompiled if followed by 0-9 numeric chars
- when emitting octal escapes, always write out 3 digit octal escape codes "\nnn".
1 parent f35c501 commit a6ca278

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Version 1.07.0
66
- CVA_LIST type, CVA_START(), CVA_COPY() CVA_END(), CVA_ARG() macros will map to gcc's __builtin_va_list and __builtin_va_* macros in gcc backend
77

88
[fixed]
9-
- #881: C backend: support for varadic function parameters in gcc using __builtin_va_list type and related macros
9+
- sf.net #881: C backend: support for varadic function parameters in gcc using __builtin_va_list type and related macros
1010
- push/pop correct GL_PROJECTION matrix and GL_MODELVIEW matrix when setting up graphics screen (gothon)
1111
- fix char & wchar concatentation. For char double byte characters (such as Chinese characters), the "wstr = char & wchar" would become "wstr = char & chrw(0) & wchar" (SkyFish)
12+
- sf.net #794: literal tabs in string literals miscompiled if followed by 0-9 numeric chars
1213

1314

1415
Version 1.06.0

src/compiler/hlp-str.bas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,15 @@ function hEscape _
812812
dst += 1
813813

814814
if( c < 8 ) then
815+
dst[0] = CHAR_0
816+
dst[1] = CHAR_0
817+
dst += 2
815818
c += CHAR_0
816819

817820
elseif( c < 64 ) then
818-
*dst = CHAR_0 + (c shr 3)
819-
dst += 1
821+
dst[0] = CHAR_0
822+
dst[1] = CHAR_0 + (c shr 3)
823+
dst += 2
820824
c = CHAR_0 + (c and 7)
821825

822826
else

tests/string/literal-tab.bas

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "fbcunit.bi"
2+
3+
SUITE( fbc_tests.string_.literal_tab )
4+
5+
TEST( default)
6+
7+
'' test that literal tabs in the source file
8+
'' are correctly escaped and emitted.
9+
10+
'' careful - string is 'x' chr(9) '0' 'x' chr(9) '0' '9'
11+
dim as string a = "x 0x 1x"
12+
dim as string b = "x" & chr(9) & "0x" & chr(9) & "1x"
13+
dim as string c = !"x\t0x\t1x"
14+
dim as ubyte d(0 to 6) = { asc("x"), 9, asc("0"), asc("x"), _
15+
9, asc("1"), asc("x") }
16+
17+
CU_ASSERT( len("x 0x 1x") = 7 )
18+
CU_ASSERT( len( a ) = 7 )
19+
CU_ASSERT( len( b ) = 7 )
20+
CU_ASSERT( len( c ) = 7 )
21+
22+
CU_ASSERT( a = "x 0x 1x" )
23+
CU_ASSERT( b = a )
24+
CU_ASSERT( c = a )
25+
26+
for i as integer = 0 to 6
27+
CU_ASSERT( a[i] = d(i) )
28+
CU_ASSERT( b[i] = d(i) )
29+
CU_ASSERT( c[i] = d(i) )
30+
next
31+
32+
END_TEST
33+
34+
END_SUITE

0 commit comments

Comments
 (0)