WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on October 27, 2016, 04:01:31 PM

Title: Strange error
Post by: MW4 on October 27, 2016, 04:01:31 PM
I'm getting an error I've never seen. It's opening a tiny file (31kb), so I have no idea what's up.

Here is offending code:
I tried increasing the 100 to 200 no difference.

str = Num2Char (12)
rep = "END OF PAGE"
fs = FileSize( infileX )
binbuf = binaryalloc( fs+100 )
ret = BinaryRead( binbuf, infileX )
num = BinaryReplace( binbuf, str, rep ,0)
BinaryWrite( binbuf, outfileX )
Title: Re: Strange error
Post by: snowsnowsnow on October 27, 2016, 09:10:07 PM
How many formfeeds are there in the data?

Just on the surface of it, it seems that since you are replacing a 1 char string with a 11 char string, every replacement increases the size of the data by 10 bytes.  So, if there are more than 10 (or 20) instances being replaced, it would overextend the buffer in the +100 (or +200) case.

Just to test this, you could try it with something like +10000 (as the increment to fs in the BinaryAlloc()).

But ultimately, it seems like you'll need to establish some kind of limit on how many replacements you'll need to be able to support.
Title: Re: Strange error
Post by: MW4 on November 01, 2016, 12:54:32 PM
not many, that's why it's weird.

But I need to actually add a linefeed to the end of that "END OF PAGE", so how can I accomplish that?

rep = "END OF PAGE @LF" ??
Title: Re: Strange error
Post by: stanl on November 02, 2016, 03:26:45 AM
rep = "END OF PAGE" : @LF