Skip to content

Development Diary 2012

Here's my software development diary. Hope you'll find some useful information here. Feel free to comment.

26 September 2012

How to run a program as a limited user on Windows XP

The following command line starts a command shell with the same rights as a limited user:

PsExec.exe -l -d c:\windows\system32\cmd.exe

Creating a desktop shortcut with the above command line can be quite useful when you want to start a program repeatedly as a limit user. In my case, I'm using PsExec to run the unit tests without the administrative privileges. You can download PsExec at the SysInternal's web site.

18 June 2012

Named return value optimization

The other day a colleague and I were debating if a piece of code written like this:

vector<string> GetTheVector()
{
	vector<string> v;
	v.reserve(..)
	v.push_back(..) //push back the # reserved strings.
	return v;
}

Could be rewritten like follows to reduce the number of memory allocations:

void GetTheVector(vector<string>& v)
{
	//caller has already called v.reserve(..)
	v.push_back(..) //push back the # reserved strings.
}

I've written a code snippet below which overrides operator new to count the number of memory allocations. At least in Visual Studio 2005 the number of memory allocations for the two variants are the same. Feel free to post the results for the compiler you are using.

#include <new>

size_t g_num_allocs = 0;

void* operator new(std::size_t size)
{
	++g_num_allocs;
	return malloc(size);
}

void* operator new(std::size_t size,
                   const std::nothrow_t &) throw()
{
	++g_num_allocs;
	return malloc(size);
}

void* operator new[](std::size_t size)
{
	++g_num_allocs;
	return malloc(size);
}

void* operator new[](std::size_t size,
                     const std::nothrow_t &) throw()
{
	++g_num_allocs;
	return malloc(size);
}

void operator delete(void *pMem) throw()
{
	if (pMem) free(pMem);
}

void operator delete(void *pMem,
                     const std::nothrow_t &) throw()
{
	if (pMem) free(pMem);
}

void operator delete[](void *pMem) throw()
{
	if (pMem) free(pMem);
}

void operator delete[](void *pMem,
                       const std::nothrow_t &) throw()
{
	if (pMem) free(pMem);
}

#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

const char* g_string = "012345678901234567890123456789";

vector<string> test0()
{
	vector<string> v;
	v.reserve(5);

	v.push_back(g_string);
	v.push_back(g_string);
	v.push_back(g_string);
	v.push_back(g_string);
	v.push_back(g_string);

	return v;
}

void test1(vector<string>& v)
{
	v.push_back(g_string);
	v.push_back(g_string);
	v.push_back(g_string);
	v.push_back(g_string);
	v.push_back(g_string);
}

int main(int argc, char* argv[])
{
	{
		g_num_allocs = 0;

		const vector<string>& v = test0();
		printf("# new in test0: %d\n", g_num_allocs);

		printf("v[0]=%s\n\n", v[0].c_str());
	}

	{
		g_num_allocs = 0;

		vector<string> v;
		v.reserve(5);
		test1(v);
		printf("# new in test1: %d\n", g_num_allocs);

		printf("v[0]=%s\n\n", v[0].c_str());
	}

	return 0;
}

/* Outputs:

Compiler: Visual studio 2005
Compiler flags /O2 /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" 
               /D "_UNICODE" /D "UNICODE" /FD /EHsc /MT 
               /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 
               /nologo /c /Wp64 /Zi /TP /errorReport:prompt

# new in test0: 11
v[0]=012345678901234567890123456789

# new in test1: 11
v[0]=012345678901234567890123456789

*/
02 June 2012

Some symbols not found when debugging a mini-dump

I'm currently looking at a user's crash dump and noticed that I did not get a complete call stack. This usually happens when symbols are not loaded for all modules that participate in the callstack. The Output window in Visual Studio reports missing symbols for wininet.dll, normaliz.dll, urlmon.dll, iertutil.dll and ieframe.dll which is suprising since I've set up Visual Studio to download symbols from http://msdl.microsoft.com/download/symbols.

Anyone else run into this problem? Could the issue be that the files have been modified on the user's machine so the checksum does not match any known symbols at the symbol servers, or is there any additional symbol servers URL that should be specified?

Visual Studio Output

wininet.dll *C:\WINDOWS\system32\wininet.dll N/A N/A No matching binary found. 4 8.00.6001.18702 3/8/2009 1:34 PM 63000000-630E6000 freefixer.0.62.dmp: Native

ntdll.dll C:\tmp\symbolcache\ntdll.dll\4802c25eb6000\ntdll.dll Symbols loaded (source information stripped). C:\tmp\symbolcache\ntdll.pdb\1751003260CA42598C0FB326585000ED2\ntdll.pdb 2 5.01.2600.5512 4/14/2008 4:33 AM 7C910000-7C9C6000 freefixer.0.62.dmp: Native

Broken call stack

ieframe.dll!01e8ffec() 	
shell32.dll!CRegFolder::BindToObject()  + 0x32 bytes	
shell32.dll!CWebViewFolderContents::CConnectionPointForwarder::Release()  + 0x11 bytes	
ntdll.dll!_RtlFreeHeap@12()  + 0x130 bytes	
ieframe.dll!01e8ffec() 	
shell32.dll!CRegFolder::BindToObject()  + 0x32 bytes	
shell32.dll!CWebViewFolderContents::CConnectionPointForwarder::Release()  + 0x11 bytes	
ntdll.dll!_RtlFreeHeap@12()  + 0x130 bytes

Comments

LINO writes

-2 thumbs

CIAO COME FACCIO A TOGLIERE DAL PC "DISTRIBUTED COMPUTING EXPERIMENT" ' E' UN VIRUS CHE COSA SVOLGE ? GRAZIE SCUSAMI DEL DISTURBO CIAO

# 20 Jan 2014, 7:51

Roger Karlsson writes

-1 thumb

@Lino: The program listed as "DISTRIBUTED COMPUTING EXPERIMENT" is a BitCoin miner. I think you should remove it from your machine.

I've developed a tool called FreeFixer, designed to remove unwanted software, such as the BitCoin miner that's running on your computer. You can download it here:

http://www.freefixer.com/

# 20 Feb 2014, 8:16

Fran Mart─źnez writes

1 thumb

i have no idea how this got on my pc nor do i know what it is for.
please advise me what to do with it

# 6 Dec 2015, 9:01

Leave a reply