[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Menu

#1122 StrCpy maxlen inconsistent behavior

2.0 Series
closed-fixed
nobody
None
5
2016-12-05
2015-11-16
Marshall
No

StrCpy $R0 "sometext" ""
;$R0 is still "sometext"
This is expected.

However,
StrCpy $R1 ""
StrCpy $R0 "sometext" $R1
;$R0 is now ""
This is not expected.

Looks like the maxlen parameter is evaluated at compile time instead of runtime, which leads to inconsistent behavior when using variable vs literal string.

Discussion

  • Anders

    Anders - 2015-11-17

    The presence of the maxlen parameter is determined at compile time and if present, is evaluated at run-time.

    Your problematic StrCpy ends up as 'StrCpy $R0 "sometext" 0' (at run-time) because $R1 needs to be converted to a number and "" is not a number so you get 0.

    If you don't know at compile time whether or not you want to truncate the string then you need to set the maxlen parameter variable to ${NSIS_MAX_STRLEN}.

     
  • Marshall

    Marshall - 2015-11-17

    I understand, but think this is rather unintuitive.
    From my pov the parameter is present at compile time in the first example - it's "" as opposed to not present.

    If a function relies on outside input for maxlen then it would have to test for empty string and replace with ${NSIS_MAX_STRLEN} itself. I just think this should be handled by the engine rather than the script so that literal "" vs variable empty string behave the same way.

    At the very least the behavior should be documented.

     
    • Anders

      Anders - 2015-11-17

      The only reason it accepts "" in the first place is so you can do StrCpy $0 "foo" "" -1. Meaning, it allows you to specify the start offset without specifying maxlen.

       
  • Anders

    Anders - 2016-12-05
    • status: open --> closed-fixed
     

Log in to post a comment.