Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD @REPEAT function

Jan
616
15
@REPEAT[x,20003] works on my computer.
@REPEAT[x,20004] fails on my computer.
Code:
C:\temp> echo %@len[%@repeat[x,20003]]
20003

C:\temp> echo %@len[%@repeat[x,20004]]
TCC: (Sys) The parameter is incorrect.
"%@repeat[x,20004]"
The documentation, while true, is inaccurate.
Take Command Help v. 16.0 said:
@REPEAT[char,count] : Returns the character char repeated count times (count may not exceed 32,767).

Edit: TCC LE 13.06.77 works up to 32766.
Code:
C:\temp> echo %@LEN[%@REPEAT[x,32766]]
32766

C:\temp> echo %@LEN[%@REPEAT[x,32767]]
TCC: (Sys) The parameter is incorrect.
 "%@REPEAT[x,32767]"
 
Last edited:
In your link you seem to be talking about command line length, this limit speaks of character count in a "function", so if a function generates a string greater than 20000 (it seems to be actually 20003), the TCC function tell you off for passing a parameter it knows will generate a string that it can't handle.
 
In your link you seem to be talking about command line length, this limit speaks of character count in a "function", so if a function generates a string greater than 20000 (it seems to be actually 20003), the TCC function tell you off for passing a parameter it knows will generate a string that it can't handle.
It also happens with "ECHO %@REPEAT[x,20004]" where the (only) function has only 7 characters in it.
 
The documentation for @REPEAT should read "(count may not exceed 20000)" because the string size limitation for functions supercedes the limitation on @REPEAT of 32767.
 
The documentation for @REPEAT should read "(count may not exceed 20000)" because the string size limitation for functions supercedes the limitation on @REPEAT of 32767.
But if you "ECHO %@REPEAT[x,20004]" you're only putting 7 characters into a function..
"ECHO %@REPEAT[x,30000]" works in TCC versions 13 and 14.
 
All below report the function @REPEAT, to which the maximum command line length apply, both for unexpanded and fully expanded. In the examples ECHO %@REPEAT[x,#] should be limited only by command line length, not function argument length.
In V12 and older the limit is listed as 8,191; not tested.
In V13 and V14 the actual limit is 32,766 characters; documented limit is 32,767.
In V15 and V16 actual limit is 20,003 characters; documented limit is 32,767.
 
But the error is "TCC: (Sys) The parameter is incorrect." and since "x,20004" and "x,20003" are both 7 characters it implies that it doesn't mean this. So when @REPEAT begins to construct the string it hits one of the internal limits (see limits in HELP). Pick one, there are a few limit here that are 20000, my vote is on "character count in any function" because it does restrict it to the parameters, the resulting string of the function can't be greater than 20000 characters either.
 
But the error is "TCC: (Sys) The parameter is incorrect." and since "x,20004" and "x,20003" are both 7 characters it implies that it doesn't mean this. So when @REPEAT begins to construct the string it hits one of the internal limits (see limits in HELP). Pick one, there are a few limit here that are 20000, my vote is on "character count in any function" because it does restrict it to the parameters, the resulting string of the function can't be greater than 20000 characters either.
I dunno! It used to work and now it doesn't. If the limit were on "character count returned by any function" your argument would make more sense (and @REPEAT's documentation would be wrong). I suppose Rex will change something so that @REPEAT's behavior and documentation agree.

I can't figure out what's going on.
Code:
v:\> echo %@len[xxxxxxxxxxxx%@repeat[x,20000]]
TCC: The argument is too long "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(snip)
I suppose that's the argument to @LEN. But I can give @LEN an environment variable whose length is over 22000 and it doesn't complain (and quietly gives the wrong result).
Code:
v:\> set zzz=%@repeat[x,11000]

v:\> set zzz=%zzz %@repeat[x,11000]

v:\> set zzz | wc -c
  22003

v:\> echo %@len[%zzz]
0
 
We agreed with you that 7 characters do not make the function exceed its invocation limit. Until V12 this function was limited to 8,191 repetitions. This was increased since V13 to 32,767, which was never valid due to line termination. However, versions 13 and 14 both accepted a repetition count of 32,766. I do not know what changed in V15 and remained in V16, and honestly I think 20,000 repetitions is sufficient, IMHO the bug is the difference between behavior and documentation. I would not care to second guess what caused the discrepancy.
 
To me it looks like the limitations in the HELP limits are now superceding the other maximum limits. The fact that v13 and v14 works could be a crash waiting to happen in the form of a buffer overrun, if functions only allocate 20000 characters and you force it to process 32767 characters. It appears that the documentation is wrong, in that 32,767 is not the upper limit for @repeat and how the 20000 character limit is handle within functions and possible environment variables is probably faulty. Vince's example of "echo %@len[xxxxxxxxxxxx%@repeat[x,20000]]" appears to be a 20000 character issue but it just doesn't seem to be handle properly.
 
Last edited:
You are fantasizing over the internals of TCC. My WAG is that the opposite of the "crash waiting to happen in the form of a brush overrur": the buffer is ample, but no longer permitted to use all that is available. Why? Because knowing Rex Conn, he would first do ample beta testing after the design. And another WAG: a typographic error in the list of the table of limitations caused the discrepancy between documentation and behavior.
 
@REPEAT[x,20003] works on my computer.
@REPEAT[x,20004] fails on my computer.
Code:
C:\temp> echo %@len[%@repeat[x,20003]]
20003

C:\temp> echo %@len[%@repeat[x,20004]]
TCC: (Sys) The parameter is incorrect.
"%@repeat[x,20004]"
The documentation, while true, is inaccurate.


Edit: TCC LE 13.06.77 works up to 32766.
Code:
C:\temp> echo %@LEN[%@REPEAT[x,32766]]
32766

C:\temp> echo %@LEN[%@REPEAT[x,32767]]
TCC: (Sys) The parameter is incorrect.
"%@REPEAT[x,32767]"

WAD. The maximum argument size was reduced because users wanted more recursion depth (in commands like DIR) and nobody cared (until now, and probably not now either) about 32K arguments. The documentation wasn't updated in all the possible places it could appear (though it was in most). I will correct the docs for the next build.
 

Similar threads

Back
Top