Thread overview
Finding unsafe line of code
Dec 29
Vino
Dec 29
Vino
Jan 01
Vino
December 29
Hi All,

Is there a way to find or test which line of a give code is not safe(possible memory corruption).


From,
Vino.B
December 29
On Friday, 29 December 2017 at 08:21:10 UTC, Vino wrote:
> Hi All,
>
> Is there a way to find or test which line of a give code is not safe(possible memory corruption).
>
>
> From,
> Vino.B

That question needs to be refined ;-)
December 29
On Friday, 29 December 2017 at 09:19:13 UTC, codephantom wrote:
> On Friday, 29 December 2017 at 08:21:10 UTC, Vino wrote:
>> Hi All,
>>
>> Is there a way to find or test which line of a give code is not safe(possible memory corruption).
>>
>>
>> From,
>> Vino.B
>
> That question needs to be refined ;-)

Hi,

  Let me re-frame the question with an example, as the Dsafe the below line of code is considered as unsafe(Pointer arithmetic), so let imagine that we have several similar line of code, how do we find such unsafe line, does the compiler check these unsafe code and complain while compiling a .d program or do we need to pass any compiler arguments to perform these check while compiling the code or do we need to manually perform an analysis of each line of code and correct the same in case if we find any unsafe code.


ini[10] a;
int* p = &a[0];
for (size_t i=0; i <= 10; i++)
p[i] = ...;

From,
Vino.B
December 29
On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote:
>
>   Let me re-frame the question with an example, as the Dsafe the below line of code is considered as unsafe(Pointer arithmetic), so let imagine that we have several similar line of code, how do we find such unsafe line, does the compiler check these unsafe code and complain while compiling a .d program or do we need to pass any compiler arguments to perform these check while compiling the code or do we need to manually perform an analysis of each line of code and correct the same in case if we find any unsafe code.
>
>
> ini[10] a;
> int* p = &a[0];
> for (size_t i=0; i <= 10; i++)
> p[i] = ...;
>
> From,
> Vino.B

Is this what you're looking for?

https://dlang.org/spec/function.html#safe-functions

Just annotate your functions with @safe (as @system is the default).
December 29
On Friday, 29 December 2017 at 10:23:24 UTC, codephantom wrote:
> On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote:
>>
>>   Let me re-frame the question with an example, as the Dsafe the below line of code is considered as unsafe(Pointer arithmetic),
...
>>
>> ini[10] a;
>> int* p = &a[0];
>> for (size_t i=0; i <= 10; i++)
>> p[i] = ...;
>>
>> From,
>> Vino.B
>
> Is this what you're looking for?
>
> https://dlang.org/spec/function.html#safe-functions
>
> Just annotate your functions with @safe (as @system is the default).

Or if that's not possible, you can add runtime checks with ASan: http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html

-Johan

January 01
On Friday, 29 December 2017 at 10:33:16 UTC, Johan Engelen wrote:
> On Friday, 29 December 2017 at 10:23:24 UTC, codephantom wrote:
>> On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote:
>>>
>>>   Let me re-frame the question with an example, as the Dsafe the below line of code is considered as unsafe(Pointer arithmetic),
> ...
>>>
>>> ini[10] a;
>>> int* p = &a[0];
>>> for (size_t i=0; i <= 10; i++)
>>> p[i] = ...;
>>>
>>> From,
>>> Vino.B
>>
>> Is this what you're looking for?
>>
>> https://dlang.org/spec/function.html#safe-functions
>>
>> Just annotate your functions with @safe (as @system is the default).
>
> Or if that's not possible, you can add runtime checks with ASan: http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html
>
> -Johan

Hi,

  Tried to install LDC on Windows 7, but getting the below errors while compiling

Installed s/w
.Net 4.7.1
.Net Core Runtime 2.0.4
.Net SDK 2.1.3
Windows SDK 10.0.16299.15

Environment Variables Set:

NETFXSDKDir = C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x86(System/User)
LDC_VSDIR = C:\Program Files (x86)\Microsoft Visual Studio\2017\Community(System)

Error:
C:\Users\bheev1\Desktop\Current\Script\Complied-64>ldc2 -fsanitize=address -g nscleaner.d
LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'
Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\HostX64\x64\link.exe failed with status: 1181

From,
Vino.B