cpp - Dave's Blog

Search
My timeline on Mastodon

Tweet from David_Risney

2015 Aug 14, 2:20
CreateRemoteThread is much easier to use to crash a remote process than its intended purpose: https://github.com/david-risney/CrashProcess/blob/master/CrashProcess/CrashProcess.cpp …
PermalinkComments

Retweet of KevinJHill

2015 Jul 22, 8:04
The Microsoft Edge @MSEdgeDev team is hiring a Senior Software Engineer! http://bit.ly/1CRaQz8 . Help us make the web better #cpp #jobs
PermalinkComments

Bug Spotting: Smart pointers and parameter evaluation order

2011 Oct 19, 5:58
The following code works fine. I have a ccomptr named resolvedUri and I want to update its hostname so I do the following:
        CreateIUriBuilder(resolvedUri, 0, 0, &builder);
builder->SetHost(host);
builder->CreateUri(0xFFFFFFFF, 0, 0, &resolvedUri);


But the following similar looking code has a bug:
    ResolveHost(resolvedUri, &resolvedUri);


The issue is that doing &resolvedUri gets the address of the pointer but also clears out the pointer due to the definition of my smart pointer class:
    operator T**()  
{
T *ptrValue = mPtrValue;
mPtrValue->Release();
mPtrValue = NULL;
return &ptrValue;
}


In C++ there’s no guarantee about the order in which parameters for a function or method are evaluated. In the case above, &resolvedUri clears out the ccomptr before evaluating resolvedUri.Get() and so ResolveHostAlias gets a nullptr.

An interesting and related thread on stack overflow on undefined behavior in C++.
PermalinkCommentsc++ technical bug programming smart-pointer cpp

Command line for finding missing URLACTIONs

2011 May 28, 11:00

I wanted to ensure that my switch statement in my implementation of IInternetSecurityManager::ProcessURLAction had a case for every possible documented URLACTION. I wrote the following short command line sequence to see the list of all URLACTIONs in the SDK header file not found in my source file:

grep URLACTION urlmon.idl | sed 's/.*\(URLACTION[a-zA-Z0-9_]*\).*/\1/g;' | sort | uniq > allURLACTIONs.txt
grep URLACTION MySecurityManager.cpp | sed 's/.*\(URLACTION[a-zA-Z0-9_]*\).*/\1/g;' | sort | uniq > myURLACTIONs.txt
comm -23 allURLACTIONs.txt myURLACTIONs.txt
I'm not a sed expert so I had to read the sed documentation, and I heard about comm from Kris Kowal's blog which happilly was in the Win32 GNU tools pack I already run.

But in my effort to learn and use PowerShell I found the following similar command line:

diff 
(more urlmon.idl | %{ if ($_ -cmatch "URLACTION[a-zA-Z0-9_]*") { $matches[0] } } | sort -uniq)
(more MySecurityManager.cpp | %{ if ($_ -cmatch "URLACTION[a-zA-Z0-9_]*") { $matches[0] } } | sort -uniq)
In the PowerShell version I can skip the temporary files which is nice. 'diff' is mapped to 'compare-object' which seems similar to comm but with no parameters to filter out the different streams (although this could be done more verbosely with the ?{ } filter syntax). In PowerShell uniq functionality is built into sort. The builtin -cmatch operator (c is for case sensitive) to do regexp is nice plus the side effect of generating the $matches variable with the regexp results.
PermalinkCommentspowershell tool cli technical command line

Kevin Frei @ NWCPP: Exception Handling Cost

2010 May 10, 7:23"Kevin Frei - Exception Hanlding Cost September 2006 meeting of the Northwest C++ Users Group. Discussion of the assembly language cost of exception handling on the x86 Windows and x64 Windows platform"PermalinkCommentsC++ programming language exception microsoft windows performance technical video

/EP (Preprocess to stdout Without #line Directives) (C++)

2008 Jan 28, 2:42Use this option with cl.exe (the Visual Studio C/C++ compiler) to see what your files look like after all the #define macro magic occurs. Useful when debugging crufty or organic macros.PermalinkCommentsmicrosoft msdn reference c++ cpp preprocessor tool compiler cl

Lazy

2003 Mar 8, 8:15Finals week is closing in quickly. This quarter seemed to go by faster than usual. With the end of the quarter almost here I've got a variety of assignments to finish. Today is supposed to be the day I work on them all, but I'm easily distracted. For instance, I had read Ken Thompson's Reflections on Trusting Trust a few days ago. As the author suggested, I tried writing my own self-reproducing program. Rather than brevity, I went for clarity and good style. That was my intent anyway. Now I'm avoiding work by writing in this journal. Last night I lost my money fairly early on during poker. After that Scott gave me a dollar which, surprisingly, lasted me much longer than the previous five. Though despite that, It was a good time.PermalinkComments
Older Entries Creative Commons License Some rights reserved.