Re: druntime giving wrong line for copy assert?

2019-04-30 Thread Bastiaan Veelo via Digitalmars-d-learn

On Tuesday, 30 April 2019 at 13:59:52 UTC, Rudy Raab wrote:
The error was on line 36, which is the format, not my bad 
slice. Is there a reason for this, or is it a bug


The message is correct when not using dub:
https://run.dlang.io/is/chFTOY

I suspect that if you remove the dub related lines and put it in 
an empty dub project, it will produce a correct message. So it 
looks like a bug in dub from where I am sitting. Maybe dub adds 
lines behind the scene?


Bastiaan.


druntime giving wrong line for copy assert?

2019-04-30 Thread Rudy Raab via Digitalmars-d-learn
I didn't want to immediately declare this a compiler/runtime bug 
without making sure I wasn't crazy/misinterpreting things.


Backstory is this: I was writing a library for dealing with some 
special corporate data to (de)serialize to/from a binary format 
and tweaking things to get the output to match a known good 
implementation in C#. I had a unittest set up to round-trip data 
from binary -> class instance -> back to binary and ensure input 
and output match.


At one point I got an assert failure in an odd place; it seemed 
to be coming from inside std.format.format. So I wrote a simple 
test program to recreate the issue:


---
#!/usr/bin/env dub
/+ dub.sdl:
name "hello"
+/

import std.stdio;
import std.datetime;
import std.regex;
import std.base64;
import std.string;
import std.algorithm;

private immutable string[] months = ["Jan", "Feb", "Mar", "Apr", 
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];


void main()
{
string dstr = "29-Apr-2019 11:04";
SysTime dateProgrammed;

ubyte[] full = new ubyte[128];

auto m = matchFirst(dstr, 
regex(r"([0-9]{2})-([A-Z][a-z]{2})-([0-9]{4}) 
([0-9]{2}):([0-9]{2})"));

assert(m.length > 0, "Date string is invalid");
import std.conv: to;
DateTime d = DateTime(1990, 1, 1);
d.month = to!Month(months.join.indexOf(m[2])/3+1);
d.year = m[3].to!short;
d.day = m[1].to!ubyte;
d.hour = m[4].to!ubyte;
d.minute = m[5].to!ubyte;
dateProgrammed = SysTime(d, 0.seconds);

copy("test_string".representation, full[8..16]);

import std.format: format;
string date = format!("%d-%3s-%d 
%02d:%02d")(dateProgrammed.day,

months[dateProgrammed.month-1], dateProgrammed.year,
dateProgrammed.hour, dateProgrammed.minute);
copy(date.representation, full[24..44]);

Base64.encode(full).writeln;
}
---

The problem is on line 33, the copy of "test_string". The slice 
to copy it into is too short. But when I run it with dub, the 
output is this:

---
core.exception.AssertError@C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\mutation.d(373):
 Cannot copy a source range into a smaller target range.

0x0043BE49 in _d_assert_msg
0x0040252B in _Dmain at \test_format_assert.d(36)
0x0043B96B in void rt.dmain2._d_run_main(int, char**, extern (C) 
int function(char[][])*).runAll().__lambda1()
0x0043B8ED in void rt.dmain2._d_run_main(int, char**, extern (C) 
int function(char[][])*).runAll()

0x0043B787 in _d_run_main
0x0043B518 in main at \test_format_assert.d(7)
0x0048CED5 in mainCRTStartup
0x767A0419 in BaseThreadInitThunk
0x7730662D in RtlGetAppContainerNamedObjectPath
0x773065FD in RtlGetAppContainerNamedObjectPath
---

The error was on line 36, which is the format, not my bad slice. 
Is there a reason for this, or is it a bug somewhere?


Blog Post #0031 - An Image on a Menu

2019-04-30 Thread Ron Tarrant via Digitalmars-d-learn

Hi all,

Time for another exciting adventure in GtkD-land. For your 
perusal: how to put images and icons in a menu. You'll find it 
right over here: 
http://gtkdcoding.com/2019/04/30/0031-imagemenuitem.html


Re: Erasing passwords from ram?

2019-04-30 Thread Dukc via Digitalmars-d-learn

On Tuesday, 30 April 2019 at 08:31:40 UTC, Kagamin wrote:

You better obfuscate the password on client side.


No, this particular password does not come from clients. Rather, 
it's given by server maintainer and used to generate passcodes 
that are then distributed to clients.


Re: Erasing passwords from ram?

2019-04-30 Thread Kagamin via Digitalmars-d-learn

You better obfuscate the password on client side.


Erasing passwords from ram?

2019-04-30 Thread Dukc via Digitalmars-d-learn
I am currently programming a server. So I got the idea that after 
I've generated all the hashes I need from a password, I want to 
erase it from RAM before discarding it, just to be sure it won't 
float around if the server memory is exposed to spyware by some 
buffer overflow. Is this wise caution, or just being too paranoid?


And if it is worthwhile, do I have to do this:
```
foreach(ref part; cast(ubyte[]) rootPassword) 
volatileStore(&part, 0);

```

Or, can I rely on that the compiler won't optimize this out?
```
rootPassword[] = '\0'
```

`rootPassword` is allocated on the heap, but only locally 
referred to.