viewpoint-particle

Author Topic: Data to store would overrun binary buffer error  (Read 1919 times)

Arulrajah

  • Newbie
  • *
  • Posts: 7
    • IT Services
Data to store would overrun binary buffer error
« 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)
Regards
Arul

stanl

  • Pundit
  • *****
  • Posts: 1777
Re: Data to store would overrun binary buffer error
« Reply #1 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.

Arulrajah

  • Newbie
  • *
  • Posts: 7
    • IT Services
Re: Data to store would overrun binary buffer error
« Reply #2 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 ?
Regards
Arul

kdmoyers

  • Sr. Member
  • ****
  • Posts: 488
Re: Data to store would overrun binary buffer error
« Reply #3 on: June 28, 2018, 01:12:56 pm »
Very large indeed.  An ordinary PC can easily create a 10 megabyte buffer. 
-K
The mind is everything; What you think, you become.

JTaylor

  • Pundit
  • *****
  • Posts: 1914
    • Data & Stuff Inc.
Re: Data to store would overrun binary buffer error
« Reply #4 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

stanl

  • Pundit
  • *****
  • Posts: 1777
Re: Data to store would overrun binary buffer error
« Reply #5 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=‘


Arulrajah

  • Newbie
  • *
  • Posts: 7
    • IT Services
Re: Data to store would overrun binary buffer error
« Reply #6 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.
Regards
Arul