-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use SString type - PathString for path allocations in binder. #1589
Conversation
@@ -65,8 +65,11 @@ namespace BINDER_SPACE | |||
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW)); | |||
} | |||
|
|||
IF_FAIL_GO(StringCbCopy(szPath, sizeof(szPath), pszName)); | |||
|
|||
WCHAR * szPath = szPathString.OpenUnicodeBuffer(MAX_LONGPATH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of using variable size optimized buffer class is that we should be allocating only what is needed whenever possible. We know exactly on how much we need to allocate here - so we should only allocate as much.
@jkotas @janvorli @JeremyKuhne : Added commit to replace allocations that are in jeremy's linux longpath change. |
@@ -1006,6 +1006,9 @@ typedef InlineSString<512> StackSString; | |||
// be needed is small and it's preferable not to take up the stack space. | |||
typedef InlineSString<32> SmallStackSString; | |||
|
|||
// To be used specifically for path strings. | |||
typedef InlineSString<512> PathString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this 256 (=existing MAX_PATH). Also, I would make the size much smaller in debug builds to make sure that we exercise the buffer allocation path.
#ifdef _DEBUG
// Make the size smaller in debug builds to exercise the buffer allocation path
typedef InlineSString<32> PathString;
#else
typedef InlineSString<256> PathString;
#endif
@Priya91 I went through all changes and left comments. |
9e183c3
to
a2b8a58
Compare
@jkotas I've submitted a new commit with the PR feedback, please review for merge. Thanks! |
WCHAR * pPath = new (nothrow) WCHAR[MAX_LONGPATH]; | ||
if (pPath == NULL) | ||
{ | ||
WCHAR pPathStack[MAX_LONGPATH]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling here should be:
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: pPathStack
in your original code is guaranteed to be allocated on stack only by the closing }
of the scope - pPath
would be a dangling pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand the purpose of this construct. The pPathStack will be allocated always on the stack, so why do we allocate the pPath at all? And for compilers that would reuse the frame space of the pPathStack after it goes out of scope at the end of the block, this is even dangerous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I just realised that. Didn't know how to handle NULL here.
f0fae35
to
e5789d9
Compare
@jkotas @janvorli @JeremyKuhne rebased the feedback commits into a single commit. When this passes CI run, is it good to merge? |
BINDER_LOG_STRING(W("combined path"), tempResultPath); | ||
} | ||
else | ||
PathString tempResultPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could combine it directly into the combinedPath instead of creating the tempResultPath.
@dotnet-bot test this please. |
WCHAR * pPath = new (nothrow) WCHAR[MAX_LONGPATH]; | ||
if (pPath == NULL) | ||
{ | ||
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be return FALSE;
- this function does not return HRESULT
.
LGTM othewise |
Respond to PR feedback. Fix test failures in mscoree.
Use SString type - PathString for path allocations in binder.
Use SString type - PathString for path allocations in binder. Commit migrated from dotnet/coreclr@bdc5bce
@jkotas @janvorli @JeremyKuhne