STL breaks after installing Microsoft Security Advisory 973882

After installing through Microsoft Update Vulnerabilities in Microsoft Active Template Library (ATL) Could Allow Remote Code Execution STL broke with the following error:
c:\program files\microsoft visual studio 9.0\vc\include\xutility(2764) : error C3861: '_Swap_adl': identifier not found

Most probably, this is caused by accidentally deleted the following function:
template inline
   void _Swap_adl(_Ty& _Left, _Ty& _Right)
   { // exchange values stored at _Left and _Right, using ADL
      swap(_Left, _Right);
   }

Placing this code back somewhere (I placed directly in xutility), fixed this problem. Not sure if there are any side effects. Most probably Microsoft will issue another fix.

Related knowledge base articles:
Description of the security update for Microsoft Visual Studio 2008 Service Pack 1: July 28, 2009
Microsoft Security Advisory: Vulnerabilities in Microsoft Active Template Library (ATL) could allow remote code execution
MS09-035: Vulnerabilities in Visual Studio Active Template Libraries could allow remote code execution

Affected system:

  • Windows XP with SP3
  • Visual Studio 2008 Professional with SP1 (Version 9.0.30729.1 SP)

Update. The following steps restores std::vector class without need to modify any headers:

  1. Uninstall the security update (Security Update for Microsoft Visual Studio 2008 Service Pack 1 – KB971092).
  2. Re-install Microsoft Visual Studio 2008 Service Pack 1 (KB945140).
  3. Re-install the security update – KB971092.

Update 2 (15 Aug 2009).

Microsoft created support topic: You receive a compile error in your ATL project after you install the Windows SDK 6.1 with Visual Studio 2008 SP1

Microsoft Windows SDK Blog: Installing Windows SDK for Server 2008 (v6.1) after VS2008 SP1 causes conflicts with Security Update (KB971092)

Batch script to test if folder / directory is empty

Yesterday I needed a Dos batch script to check if folder is empty. A little Google search revealed some methods:

  • Using dir and find commands, does not work on non-english Windows versions: www.computing.net
  • Using dir command with /a-d, does not work for folders: www.computing.net
  • Using dir and findstr commands, does not work on non-english Windows versions: windowsitpro.com

If you want something done right do it yourself. Here is a my script:
@echo off
for /F %%i in ('dir /b "c:\test directory\*.*"') do (
   echo Folder is NON empty
   goto :EOF
)
echo Folder is empty or does not exist

Update Sep 21, 2011 – added “or does not exist”. Thanks to the Thump.
Update Jul 5, 2013 – for more code examples see the comments!

Join (merge / concatenate) split files: Windows or Linux

Sometimes you have to join two files together. There are plenty of tools for file spitting and joining (restoring), but I prefer the build in ones.

Use copy command under Windows:
copy /B file1.ext + file2.ext result_file.ext
“B” stands for binary file

Use cat command under Linux:
cat file1.ext file2.ext > result_file.ext

Here are two example files shown in hexadecimal and ascii:

file1.ext
00000000 31 31 31 20 61 62 63 0D   111 abc.
00000008 0A 0D 0A                  ...

file2.ext
00000000 53 65 63 6F 6E 64 20 66   Second f
00000008 69 6C 65 0D 0A            ile..

after concatenation result_file.ext contains contents of both files
00000000 31 31 31 20 61 62 63 0D   111 abc.
00000008 0A 0D 0A 53 65 63 6F 6E   ...Secon
00000010 64 20 66 69 6C 65 0D 0A   d file..