digitalmars.D - winsamp.d and -O
- =?ISO-8859-1?B?Lg==?= (10/10) Jun 14 2011 charset="ISO-8859-1"
 - Dmitry Olshansky (5/15) Jun 14 2011 Seems like a bad joke, so file a bug.
 - Andrej Mitrovic (3/3) Jun 14 2011 LOL how the hell did that get in there? I remember I was updating
 - Andrej Mitrovic (13/16) Jun 14 2011 Oh wait, it's not my fault! It's a demonstration, see:
 - Dmitry Olshansky (6/23) Jun 14 2011 I think generic 'windows sample' is _not_ about null pointer dereference...
 - Andrej Mitrovic (9/12) Jun 14 2011 Actually there's another problem. In WinMain, this line:
 - Dmitry Olshansky (6/18) Jun 14 2011 Makes sense. I'd better stop arguing this cause, and read more on that
 - Andrej Mitrovic (2/2) Jun 14 2011 If you're feeling adventurous you could always put up a Linux GUI
 - Robert Clipsham (7/9) Jun 14 2011 I believe xcb is what's recommended, it's faster and more lightweight.
 - Andrej Mitrovic (1/1) Jun 14 2011 Well, turns out there's no sign of the samples folder on github. :/
 - Andrej Mitrovic (28/28) Jun 14 2011 To make the example compile with optimizations, you have to trick the
 
charset="ISO-8859-1" Content-Transfer-Encoding: base64 VGhlIHdpbnNhbXAuZCBpcyBkaXN0cmlidXRlZCB3aXRoIERNRC4gIEl0J3MgT0sgd2hlbiBi ZWluZyBidWlsdCBsaWtlIHRoaXM6DQogICBkbWQgd2luc2FtcCBnZGkzMi5saWIgd2luc2Ft cC5kZWYNCg0KSG93ZXZlciwgcnVubmluZyB0aGlzOg0KICAgZG1kIC1PIHdpbnNhbXAgZ2Rp MzIubGliIHdpbnNhbXAuZGVmDQp3aWxsIGlzc3VlIGEgZXJyb3IgbWVzc2FnZToNCiAgIHdp bnNhbXAuZCgzNSk6IEVycm9yOiBudWxsIGRlcmVmZXJlbmNlIGluIGZ1bmN0aW9uIFdpbmRv d1Byb2MNCg0KQ2hlY2sgaXQsIHlvdSB3aWxsIGdldCB0aGlzOg0KKihjYXN0KGludCopIG51 bGwpID0gNjY2Ow0KDQpCZWZvcmUgZmlyaW5nIGEgYnVnLCBJIHdhbnQgdG8gbWFrZSBzdXJl IGFib3V0IGl0Lg0KDQpUaGFua3Mu
 Jun 14 2011
On 14.06.2011 16:18, . wrote:
 The winsamp.d is distributed with DMD.  It's OK when being built like 
 this:
    dmd winsamp gdi32.lib winsamp.def
 However, running this:
    dmd -O winsamp gdi32.lib winsamp.def
 will issue a error message:
    winsamp.d(35): Error: null dereference in function WindowProc
 Check it, you will get this:
 *(cast(int*) null) = 666;
 Before firing a bug, I want to make sure about it.
Seems like a bad joke, so file a bug.
In all honesty it's not a good way to greet beginners.
-- 
Dmitry Olshansky
 Jun 14 2011
LOL how the hell did that get in there? I remember I was updating these samples some time ago.. maybe it was my fault. I am completely sorry if this was my fault.
 Jun 14 2011
On 6/15/11, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:LOL how the hell did that get in there? I remember I was updating these samples some time ago.. maybe it was my fault. I am completely sorry if this was my fault.Oh wait, it's not my fault! It's a demonstration, see: case IDC_BTNDONTCLICK: if (HIWORD(wParam) == BN_CLICKED) { MessageBoxA(hWnd, "You've been warned...", "Prepare to GP fault", MB_OK | MB_ICONEXCLAMATION); *(cast(int*) null) = 666; } The difference is, DMD can catch this at compile time with optimizations turned on. I don't know why. Anyway, the example is supposed to show what happens on a wrong pointer dereference.
 Jun 14 2011
On 15.06.2011 2:03, Andrej Mitrovic wrote:On 6/15/11, Andrej Mitrovic<andrej.mitrovich gmail.com> wrote:I think generic 'windows sample' is _not_ about null pointer dereference (though arguably one can consider Windows as a whole an example on GP fault and null pointer dereference in particular). -- Dmitry OlshanskyLOL how the hell did that get in there? I remember I was updating these samples some time ago.. maybe it was my fault. I am completely sorry if this was my fault.Oh wait, it's not my fault! It's a demonstration, see: case IDC_BTNDONTCLICK: if (HIWORD(wParam) == BN_CLICKED) { MessageBoxA(hWnd, "You've been warned...", "Prepare to GP fault", MB_OK | MB_ICONEXCLAMATION); *(cast(int*) null) = 666; } The difference is, DMD can catch this at compile time with optimizations turned on. I don't know why. Anyway, the example is supposed to show what happens on a wrong pointer dereference.
 Jun 14 2011
On 6/15/11, Dmitry Olshansky <dmitry.olsh gmail.com> wrote:I think generic 'windows sample' is _not_ about null pointer dereferenceActually there's another problem. In WinMain, this line: catch (Exception e) // catch any uncaught exceptions should be: catch (Throwable e) // catch any uncaught exceptions That way when a null is dereferenced you'll have the exception caught and get a nice error message. That's what this sample was supposed to demonstrate. I'll have it updated and make a pull.(though arguably one can consider Windows as a whole an example on GP fault and null pointer dereference in particular).I don't follow.
 Jun 14 2011
On 15.06.2011 2:23, Andrej Mitrovic wrote:On 6/15/11, Dmitry Olshansky<dmitry.olsh gmail.com> wrote:Makes sense. I'd better stop arguing this cause, and read more on that awesome DIP11 ;)I think generic 'windows sample' is _not_ about null pointer dereferenceActually there's another problem. In WinMain, this line: catch (Exception e) // catch any uncaught exceptions should be: catch (Throwable e) // catch any uncaught exceptions That way when a null is dereferenced you'll have the exception caught and get a nice error message. That's what this sample was supposed to demonstrate. I'll have it updated and make a pull.nvm, a pun that apparently out of date. -- Dmitry Olshansky(though arguably one can consider Windows as a whole an example on GP fault and null pointer dereference in particular).I don't follow.
 Jun 14 2011
If you're feeling adventurous you could always put up a Linux GUI example. Xlib would be the standard lib, afaik?
 Jun 14 2011
On 14/06/2011 23:50, Andrej Mitrovic wrote:If you're feeling adventurous you could always put up a Linux GUI example. Xlib would be the standard lib, afaik?I believe xcb is what's recommended, it's faster and more lightweight. This said, you'd have to be insane to work with X directly, better off using QtD or GtkD. -- Robert http://octarineparrot.com/
 Jun 14 2011
Well, turns out there's no sign of the samples folder on github. :/
 Jun 14 2011
To make the example compile with optimizations, you have to trick the
compiler so it can't determine whether it's a null dereference at
compile-time. Change the code to this:
int* p;
extern (Windows)
int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDC_BTNCLICK:
                    if (HIWORD(wParam) == BN_CLICKED)
                        MessageBoxA(hWnd, "Hello, world!", "Greeting",
                                    MB_OK | MB_ICONINFORMATION);
                    break;
                case IDC_BTNDONTCLICK:
                    if (HIWORD(wParam) == BN_CLICKED)
                    {
                        MessageBoxA(hWnd, "You've been warned...",
"Prepare to GP fault",
                                    MB_OK | MB_ICONEXCLAMATION);
                        *p = 1;
                    }
... more code ...
And then it will compile and throw at runtime when u press the dontclick button.
 Jun 14 2011








 
 
 
 Andrej Mitrovic <andrej.mitrovich gmail.com> 