Looking at operations.cpp, the function get_full_path_name_template has a couple minor issues that could use improvement.

 

First, the original buffer size used in 128.  A value of _MAX_PATH (which is 260) + 1 for the trailing nul would prevent the need to iterate, except in unusual cases.

 

The code adds a nul terminator with buf[len]=’\0’ or big_buf[len]=’\0’, but the underlying GetFullPathName call already nul-terminated the string.  It bugs me that big_buf[len] is used without checking that the new value of len is OK, and that the char form of the literal is used.  Removing these statements would avoid both issues.

 

In the past, I’ve found some APIs that don’t record the desired length correctly, so I’ve learned to be more defensive and give a little extra padding rather than the exact amount specified.  The specific bug I’ve found in Windows concerned the character set conversion code, which takes more space for intermediate results than for the final result.  They are also known for being inconsistent about counting or not counting the trailing nul.

 

In my own code, I dealt with “\\?\” specially.  Any time the string begins with “\\” (two actual backslashes) it is either a UNC name or this special escape prefix, so the function is a no-op.  The documentation for GetFullPathName says that it handles UNC names, and one of the examples is taking the escape prefix.  But the reason for using the prefix is to get around length limits and avoid automatic processing of the name, so just shorting out and returning the input unchanged will avoid the big_buf stuff and prevent any accidental unwanted alteration.

 

--John

 

 

 

 

(huge company footer follows)

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.