Typical security issues in C++: why the GC isn't your enemy

Timon Gehr timon.gehr at gmx.ch
Thu Dec 8 23:30:56 UTC 2022


On 12/8/22 21:57, Walter Bright wrote:
> On 12/6/2022 3:58 PM, Timon Gehr wrote:
>> Variables are scoped within the innermost block that they are declared 
>> in. Languages like Python that don't have block-local scoping just 
>> don't have this particular problem (there's plenty of things to 
>> dislike about Python, but this is something it got right I think):
>>
>> ```python
>> # note there is no x declared here
>> if cond:
>>      x = f()
>> else:
>>      x = g()
>> print(x)
>> ```
> 
> That looks like a matter of taste rather than righteousness.
> ...

I am quite confident that C scoping is not how it should be done, then 
people asked what I think is the right solution, so I provided that.

Almost everything is a trade-off, but this fixes the issue without 
introducing spurious behavior, limitations or syntactic incantations.

D's solution of "just put a null state into every type" is probably 
close to my least favorite part of the language. Yes, that's a 
preference, but it's backed up by more reasoning than "YMMV".

> 
>> A particularly egregious case is the do-while loop:
>>
>> do{
>>      int x=4;
>>      if(condition){
>>          ...
>>          x++;
>>      }
>>      ...
>> }while(x<10); // error
>> ```
>>
>> Just... why? x)
> 
> Because we love to annoy people.
> 

Well, for D specifically, I hope the answer is just that the reason is 
that C does it this way.


More information about the Digitalmars-d mailing list