Data to store would overrun binary buffer error

Started by Arulrajah, June 28, 2018, 09:51:49 AM

Previous topic - Next topic

Arulrajah

I am getting an error when I use the code like the one below, any help?
All I wanted to do, find and replace some characters in data.xml file.
But, multiple characters.
Master.ini file contains following;
Find=&
Replace=&
Find='
Replace='
Find="
Replace="
Find=°
Replace=°
Find=–
Replace=‘
----------------------------------------------------------------------------------------------
Winbatch code is following;

R = FileOpen("Master.ini", "READ")

Find = ""
Replace = ""

while @TRUE
x = FileRead(R)
l = StrLen (x)
If x == "*EOF*" Then Break

if StrSub(x ,1,5) == "Find=" then Find = StrSub(x,6,l-5)

if StrSub(x ,1,8) == "Replace=" then
Replace = StrSub(x,9,l-8)

str=Find
rep=Replace
dafile="C:\expodata\data.xml"
fs = FileSize( dafile )
binbuf = BinaryAlloc( fs+2048 )
ret = BinaryRead( binbuf, dafile )
num = BinaryReplace( binbuf, str, rep ,0)
;Message( "Number of '%str%' strings replaced", num )
BinaryWrite( binbuf, dafile )
BinaryFree( binbuf)

EndIf

EndWhile

FileClose (R)
Regards
Arul

stanl

An obvious answer might be to increase binbuf = BinaryAlloc( fs+2048 )  to some larger number like binbuf = BinaryAlloc( fs+10000 ),or just open the xml once and use regex to process.

Arulrajah

I didn't know that 10000 can be used in
binbuf = BinaryAlloc( fs+2048 )

Changed 2048 to 10000, it worked. Thank you very much.

What is the maximum number I can set this to ?
Regards
Arul

kdmoyers

Very large indeed.  An ordinary PC can easily create a 10 megabyte buffer. 
-K
The mind is everything; What you think, you become.

JTaylor

If your file is prone to significant file size changes you might consider using a multiplier instead of adding an amount.   This will be more accommodating, for obvious reasons. 

Jim

stanl

Just curious if this replacement works as intended. Appears you are trying to escape a dash but not sure that is ASCII 145.

Find=–
Replace=‘


Arulrajah

No. Just fails for any characters. It was working fine for a while. And stopped recently. Not sure why.
Regards
Arul