Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
len 1000 string causes printf of death #445891
09/28/14 23:47
09/28/14 23:47
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
In trying to print debugging information to diagnose a problem with an rpc call, I stumbled upon a printf-of-death. I have narrowed down at least two independent surprise behaviors with printf:
  • printf's format string argument cannot exceed 1000 characters.
  • printf's output length cannot exceed 1023 characters.
These lead not just a "Crash in script".
In Windows this is a hard crash-to-desktop. A message box says "Zorro Automaton has stopped working".
In wine i get
wine: Unhandled exception 0xc000000d in thread 18 at address 0x514658 (thread 0018), starting debugger...
winedbg: Internal crash at 0x7ed2b0b5

Verbose/diag log is empty.

Example of first bug
Code:
#define BUFFSIZE 4000
char response[BUFFSIZE];

function main() {
  int i;
  for (i = 0; i < 1023; i++) {
    response[i] = 'x';
  }
  response[1023] = 0;
  printf("\n%s", response);
}

(Crash)

Please let me know if you need a script example for the first one. (Just print a string literal longer than 1000 chars and you'll see it.)

Last edited by GPEngine; 09/28/14 23:55.
Re: len 1000 string causes printf of death [Re: GPEngine] #445892
09/28/14 23:56
09/28/14 23:56
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Change
response[1023] = 0;
to
response[1022] = 0;
= no crash

Re: len 1000 string causes printf of death [Re: GPEngine] #445893
09/28/14 23:59
09/28/14 23:59
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
strlen is not affected. So I can see that response is 1024 bytes but trying to print it kills me.

Last edited by GPEngine; 09/28/14 23:59.
Re: len 1000 string causes printf of death [Re: GPEngine] #445894
09/29/14 00:04
09/29/14 00:04
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Feature Request
strncpy , snprintf, etc.

Re: len 1000 string causes printf of death [Re: GPEngine] #445902
09/29/14 11:52
09/29/14 11:52
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
Printf prints in the message window and thus must not exceed its buffer size - I believe it's indeed 1024 characters. I have no idea why this was omitted in the manual, but I'll add it.

Using strncpy etc. is up to you. The C library functions are described in all C books. But you must add a header - look into the stdio.h header as an example.

Re: len 1000 string causes printf of death [Re: jcl] #445912
09/29/14 14:55
09/29/14 14:55
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
If you had snprintf you could replace the formatted output with a truncated output or a warning message instead of crashing.

Re: len 1000 string causes printf of death [Re: GPEngine] #445922
09/30/14 04:45
09/30/14 04:45
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
From my perspective, I had a crash bug in my Strategy. I added a printf to see what was happening. Then I had two crash bugs.

Re: len 1000 string causes printf of death [Re: GPEngine] #445926
09/30/14 08:18
09/30/14 08:18
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
Yes, I've sent a request to fix the bug by issuing an error message.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1