PrintN Bug or normal behaviour

Just starting out? Need help? Post your questions and find answers here.
gogo
User
User
Posts: 11
Joined: Wed Jan 31, 2007 11:18 am
Location: France

PrintN Bug or normal behaviour

Post 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
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

Works OK (i.e. 1901 displays many lines) with PB4.10B2 running under Windows ME, with debug on, debug off and compiled.
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

same problem with winxp sp2, only 1900 lines work correct
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PrintN Bug or normal behaviour

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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()]
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
gogo
User
User
Posts: 11
Joined: Wed Jan 31, 2007 11:18 am
Location: France

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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: )
I may look like a mule, but I'm not a complete ass.
gogo
User
User
Posts: 11
Joined: Wed Jan 31, 2007 11:18 am
Location: France

Post 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)
Post Reply