Browse Source

Changed the JS Writter to avoid access violation in the buffer.

Henrique Gottardi Werlang 2 years ago
parent
commit
337fff51c5
1 changed files with 16 additions and 16 deletions
  1. 16 16
      packages/fcl-js/src/jswriter.pp

+ 16 - 16
packages/fcl-js/src/jswriter.pp

@@ -1,4 +1,4 @@
-{ ********************************************************************* 
+{ *********************************************************************
     This file is part of the Free Component Library (FCL)
     This file is part of the Free Component Library (FCL)
     Copyright (c) 2016 Michael Van Canneyt.
     Copyright (c) 2016 Michael Van Canneyt.
        
        
@@ -29,10 +29,8 @@ uses
 Type
 Type
   {$ifdef pas2js}
   {$ifdef pas2js}
   TJSWriterString = UnicodeString;
   TJSWriterString = UnicodeString;
-  TJSWriterChar = WideChar;
   {$else}
   {$else}
   TJSWriterString = AnsiString;
   TJSWriterString = AnsiString;
-  TJSWriterChar = AnsiChar;
   {$endif}
   {$endif}
 
 
   TTextWriter = class;
   TTextWriter = class;
@@ -97,7 +95,7 @@ Type
   end;
   end;
   {$endif}
   {$endif}
 
 
-  TBufferWriter_Buffer = Array of {$ifdef fpc}byte{$else}string{$endif};
+  TBufferWriter_Buffer = Array of {$IFDEF PAS2JS}String{$ELSE}Byte{$ENDIF};
 
 
   { TBufferWriter }
   { TBufferWriter }
 
 
@@ -382,22 +380,24 @@ begin
   FCapacity:=FBufPos;
   FCapacity:=FBufPos;
 end;
 end;
 {$else}
 {$else}
-Var
-  DesLen,MinLen : Integer;
+var
+  DesLen,MinLen : Cardinal;
 
 
 begin
 begin
-  Result:=Length(S)*SizeOf(TJSWriterChar);
-  if Result=0 then exit;
-  MinLen:=Result+integer(FBufPos);
-  If (MinLen>integer(Capacity)) then
+  Result := Length(S);
+  if Result = 0 then
+    Exit;
+
+  MinLen:=Result + FBufPos;
+  if MinLen > Capacity then
     begin
     begin
-    DesLen:=(FCapacity*3) div 2;
-    if DesLen>MinLen then
-      MinLen:=DesLen;
-    Capacity:=MinLen;
+    DesLen:=(FCapacity * 3) div 2;
+    if DesLen > MinLen then
+      MinLen := DesLen;
+    Capacity := MinLen;
     end;
     end;
-  Move(S[1],FBuffer[FBufPos],Result);
-  FBufPos:=integer(FBufPos)+Result;
+  Move(S[1], FBuffer[FBufPos], Result);
+  FBufPos:=FBufPos + Result;
 end;
 end;
 {$endif}
 {$endif}