Skip to content

Commit

Permalink
Fix wstring constant merging check to calculate buffer size correctly
Browse files Browse the repository at this point in the history
We check the internal string length to see whether we can use hEscapeW().
Since all this is internal and based on the host Wstring type, we have to
check against host Wstring size.
  • Loading branch information
dkl committed Oct 23, 2016
1 parent 366b204 commit 0de1de9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/compiler/symb-const.bas
Expand Up @@ -247,11 +247,9 @@ function symbAllocWStrConst _
strlength = internalstrlen
end if

dim as integer wcharsize = typeGetSize( FB_DATATYPE_WCHAR )

'' hEscapeW() can use up to (4 * wcharsize) ascii chars per unicode char
'' hEscapeW() can use up to (4 * sizeof(wchar)) ascii chars per unicode char
'' (up to one '\ooo' per byte of wchar)
if( internalstrlen * ((1+3) * wcharsize) <= FB_MAXNAMELEN-6 ) then
if( internalstrlen * ((1+3) * sizeof( wstring )) <= FB_MAXNAMELEN-6 ) then
id = "{fbwc}"
id += *hEscapeW( sname )
else
Expand All @@ -266,7 +264,7 @@ function symbAllocWStrConst _
id_alias = *symbUniqueId( )

'' it must be declare as SHARED, see symbAllocFloatConst()
var strsize = (strlength + 1) * wcharsize
var strsize = (strlength + 1) * typeGetSize( FB_DATATYPE_WCHAR )
s = symbAddVar( @id, @id_alias, FB_DATATYPE_WCHAR, NULL, strsize, 0, dTB(), _
FB_SYMBATTRIB_SHARED or FB_SYMBATTRIB_CONST or FB_SYMBATTRIB_LITERAL, _
FB_SYMBOPT_MOVETOGLOB or FB_SYMBOPT_PRESERVECASE or FB_SYMBOPT_NODUPCHECK )
Expand Down

0 comments on commit 0de1de9

Please sign in to comment.