Page 1 of 1

PrintN Bug or normal behaviour

Posted: Wed Jun 20, 2007 3:00 pm
by gogo
Hello,

I'm using PB 4.02 on Win2k. The following code prints a lot of characters on the console.

Code: Select all

OpenConsole()
msg.s

For i=1 To 1900
  msg + "AZERTYUIOPQSDFGHJKLMWXCVBN" + #CRLF$
Next i

PrintN(msg)
PrintN(Str(Len(msg)) + " characters should be printed")  
PrintN("Finished")
Input()
CloseConsole()
OK! useless program. But if you replace '1900' in the loop by '1901' it prints the following message :

Code: Select all


53228 characters should be printed
Finished
Nothing but un single CRLF is printed on the first line.
Is it a bug or not ?

Goran

Posted: Thu Jun 21, 2007 8:16 am
by akj
Works OK (i.e. 1901 displays many lines) with PB4.10B2 running under Windows ME, with debug on, debug off and compiled.

Posted: Thu Jun 21, 2007 8:24 am
by ts-soft
same problem with winxp sp2, only 1900 lines work correct

Re: PrintN Bug or normal behaviour

Posted: Thu Jun 21, 2007 11:00 am
by PB
Probably just some limit on NT-based Windows. Why not just ensure that your
strings are no larger than 1 KB (1024 bytes), and you won't have a problem.

Posted: Thu Jun 21, 2007 12:33 pm
by srod
Completely crashed my computer to the extent that I had to remove the laptop battery in order to restart the machine! :shock:

Win xp pro sp2.

Posted: Thu Jun 21, 2007 1:16 pm
by PB
Seems that 53217 bytes is the limit for NT-based Windows:

Code: Select all

OpenConsole()
msg.s
msg=Space(53217) ; Works, but 53218 doesn't.
PrintN(msg)
PrintN(Str(Len(msg)) + " characters should be printed")
PrintN("Finished")
Input()
CloseConsole()]

Posted: Thu Jun 21, 2007 1:25 pm
by gogo
Srod, I'm really sorry if youre story is true :twisted: I never thought that I can write a 'virus' with the PrintN() function.

As PB said in his post there is a limit.
I made some other tests with version 4.10B2 on Win2k sp4.

With Unicode support in compiler option,
this code works :

Code: Select all

OpenConsole()
s1.s = Space(26608)
ReplaceString(s1," ","#",2)
PrintN(s1)
Input()
CloseConsole()
This one doesn't :

Code: Select all

OpenConsole()
s1.s = Space(26609)
ReplaceString(s1," ","#",2)
PrintN(s1)
Input()
CloseConsole()
26609 is the magic number :shock:

If I remove the Unicode support in compiler options the new magic number is : 53218 ( = 2 * 26609 ) 8)

It's a strange limitation in the PrintN() function.
Those tests work on Linux (PB 4.01).

I wasted about a day with a small piece of of code I'm working on. My code is very simple :
- Connect to a web server
- Send a HTTP message to retrieve a page
- Store the page in a string
- PrintN of the string on the console to verify

The page I was trying to retrieve weighted 70kb. With this strange PrintN behaviour I did not saw anything. :x

Posted: Thu Jun 21, 2007 1:29 pm
by srod
Srod, I'm really sorry if youre story is true I never thought that I can write a 'virus' with the PrintN() function.
No worries, just let me know your address so that I can send you the repair bill! :twisted:

Actually, before it crashed Windows threw up a message that it was closing down in order to protect my machine from being damaged!


{Note to self: never run any code produced by Gogo! :wink: )

Posted: Thu Jun 21, 2007 1:56 pm
by gogo
The program that crashed Srod's PC is 5 kb :shock:
Il love PureBasic :)

I understand why I heard to never trust too small programs. They look like very dangerous viruses. The same program in RealBasic is far more heavy ... It looks serious (even if it does nothing) :roll: But it works :wink:

Long live bloated software ! (OK, I'm definitely insane)