Strange error

Started by MW4, October 27, 2016, 04:01:31 PM

Previous topic - Next topic

MW4

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 )

snowsnowsnow

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.

MW4

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" ??

stanl

rep = "END OF PAGE" : @LF