1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WAD @REPEAT function

Discussion in 'Support' started by JohnQSmith, Apr 9, 2014.

  1. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    @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]"
     
    #1 JohnQSmith, Apr 9, 2014
    Last edited: Apr 9, 2014
  2. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    Look in the HELP and check out the "Limits", the maximum "character count in any function" is 20,000.
     
  3. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
  4. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    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.
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,877
    Likes Received:
    30
    It also happens with "ECHO %@REPEAT[x,20004]" where the (only) function has only 7 characters in it.
     
  6. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    It appears to me that the function @repeat is generating the error when it sees a count greater than 20003, not "x,20004", the 7 characters between the "[" and "]".
     
  7. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    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.
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,877
    Likes Received:
    30
    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.
     
  9. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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.
     
  10. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    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.
     
  11. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,877
    Likes Received:
    30
    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
     
  12. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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.
     
  13. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    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.
     
    #13 cgunhouse, Apr 10, 2014
    Last edited: Apr 10, 2014
  14. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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.
     
  15. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,813
    Likes Received:
    82
    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.
     
  16. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Problem solved. Thanks.
     

Share This Page