Skip to content

Commit 501d2e7

Browse files
committed
bugfix: sf.net #899 trim( wstring ) causes crash if string is single space
- In fb_wstr_CalcDiff() the original expression is optimized with a SHR expression due the divide by unsigned power of 2. This doesn't work for negative values. - Casting to intptr_t should not be needed as the pointer arithmetic alone should be sufficient to calculate distance betwee related pointers
1 parent ae9a9f3 commit 501d2e7

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Version 1.07.0
1515
- sf.net #897: length of literal wstring is miscalculated at compile time. Compile time evaluation of len(!"\u1234") was using the internal escaped string length instead of the actual codepoint length
1616
- github #137: Final -Wl flag takes precedence over previous. fbc now passes down all options from all -Wa, -Wc, and -Wl flags (William Breathitt Gray)
1717
- github #138: rtlib: freebsd: Fix deprecated use of VM_METER to use VM_TOTAL (William Breathitt Gray)
18+
- sf.net #899: trim( wstring ) causes crash if string is single space
1819

1920

2021
Version 1.06.0

src/rtlib/fb_unicode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ typedef uint8_t UTF_8;
126126
/* Calculate the number of characters between two pointers. */
127127
static __inline__ ssize_t fb_wstr_CalcDiff( const FB_WCHAR *ini, const FB_WCHAR *end )
128128
{
129-
return ((intptr_t)end - (intptr_t)ini) / sizeof( FB_WCHAR );
129+
return end - ini;
130130
}
131131

132132
static __inline__ FB_WCHAR *fb_wstr_AllocTemp( ssize_t chars )

0 commit comments

Comments
 (0)