[llvm] r192103 - Windows/Process.inc: Fix for +Asserts. &Buf[0] is not guaranteed if size is zero.

David Majnemer david.majnemer at gmail.com
Mon Oct 7 09:38:30 PDT 2013


What's wrong with Buf.data() ?

Sent from my iPhone

> On Oct 7, 2013, at 9:32 AM, Reid Kleckner <rnk at google.com> wrote:
> 
>> On Mon, Oct 7, 2013 at 11:33 AM, NAKAMURA Takumi <geek4civic at gmail.com> wrote:
>> Author: chapuni
>> Date: Mon Oct  7 10:33:30 2013
>> New Revision: 192103
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=192103&view=rev
>> Log:
>> Windows/Process.inc: Fix for +Asserts. &Buf[0] is not guaranteed if size is zero.
> 
> This is unsatisfying.  We shouldn't have to zero the memory after allocating it.  Is there a better way we can write this pattern?  The only thing I can think of is 'reserve(Size); push_back(L'\0')'.
>  
>> Modified:
>>     llvm/trunk/lib/Support/Windows/Process.inc
>> 
>> Modified: llvm/trunk/lib/Support/Windows/Process.inc
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Process.inc?rev=192103&r1=192102&r2=192103&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Support/Windows/Process.inc (original)
>> +++ llvm/trunk/lib/Support/Windows/Process.inc Mon Oct  7 10:33:30 2013
>> @@ -161,7 +161,7 @@ Optional<std::string> Process::GetEnv(St
>>    SmallVector<wchar_t, MAX_PATH> Buf;
>>    size_t Size = MAX_PATH;
>>    do {
>> -    Buf.reserve(Size);
>> +    Buf.resize(Size);
>>      Size = GetEnvironmentVariableW(&NameUTF16[0], &Buf[0], Buf.capacity());
>>      if (Size == 0)
>>        return None;
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131007/b6c59641/attachment.html>


More information about the llvm-commits mailing list