WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Arulrajah on June 28, 2018, 09:51:49 AM

Title: Data to store would overrun binary buffer error
Post by: Arulrajah on June 28, 2018, 09:51:49 AM
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)
Title: Re: Data to store would overrun binary buffer error
Post by: stanl on June 28, 2018, 11:38:10 AM
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.
Title: Re: Data to store would overrun binary buffer error
Post by: Arulrajah on June 28, 2018, 11:55:17 AM
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 ?
Title: Re: Data to store would overrun binary buffer error
Post by: kdmoyers on June 28, 2018, 01:12:56 PM
Very large indeed.  An ordinary PC can easily create a 10 megabyte buffer. 
-K
Title: Re: Data to store would overrun binary buffer error
Post by: JTaylor on June 28, 2018, 01:23:56 PM
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
Title: Re: Data to store would overrun binary buffer error
Post by: stanl on June 29, 2018, 03:26:18 AM
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=‘

Title: Re: Data to store would overrun binary buffer error
Post by: Arulrajah on July 01, 2018, 10:11:49 PM
No. Just fails for any characters. It was working fine for a while. And stopped recently. Not sure why.