Issues with Visual Studio

Posted: April 11, 2013 in Uncategorized

Unlike the other C compiler such as GCC & MingW which implements the C99 standard, Visual Studio only implements C89. As I recently compiled some C (not C++) code under VS2010 with errors, I am concerned about this.

The issue is that INFINITE, NAN, isnan() are undeclared in the <math.h> library which comes with Visual Studio. Here, a workaround is proposed for each of them.

  • Workaround for INFINITE:
  • Workaround for NAN:
#ifdef WIN32
    #ifndef NAN
        static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
        #define NAN (*(const float *) __nan)
  • Workaround for isnan():

Visual Studio comes with another function _isnan() as a replacement for isnan().

Additionally, some essential math constants – M_E, M_PI, M_LN1, M_LN10, etc – are not defined by default. To use the definitions, add the following line before you include <math.h>:


Learn more about protecting your Facebook account by reading this guide, “Guide to Facebook Security“, from

False Transfer Speed in Windows 7

False Transfer Speed in Windows 7

What an incredible transfer speed? Is it an SSD? No. It is a NTFS-formatted Kingston DT-101 G2 USB 2.0 16GB pendrive.

I notice that windows report false transfer speed when copying to a NTFS-formatted pendrive. The issue, however, is not observed when the same pendrive is formatted in FAT32. The speed displayed seems to be reading speed from my SSD into the main memory. This is because the progress bar will stop at the position shown in the screenshot and the final bit of transfer seems to take forever. The whole file is cached in the memory before being written into the pendrive, since the disk cache size is observed to increase significantly during the transfer. At the moment, however, I cannot confirm what is causing the problem because I do not find any similar issue on the internet.

Remove old linux kernels

Posted: January 12, 2013 in System Administration
Tags: ,

When upgrading linux kernel, Ubuntu does not automatically remove previous version of the kernel. Yup, it is good if you keep the previous version, so that if anything crashes (eg: your driver is incompatible with the new kernel), you may revert to the old kernel. However, sometimes the old kernels may accumulate and fill up your disk space. Therefore, if you are running fine on your current kernel, you can choose to remove the old ones to free up some disk space. Here’s how you can do it.

  1. Launch your preferred package or software manager. The new Ubuntu ships with Ubuntu Software Center, so you may use that.
  2. Under installed software, search for linux-image.
  3. Remove all kernels other than your current version. (You may find out your kernel version by executing “uname -r” on the terminal.) Using the screenshot below as example, the current kernel version is 3.2.0-35-generic-pae. So we will remove other kernels, which are 3.2.0-23-generic-pae, 3.2.0-24-generic-pae, and 3.2.0-29-generic-pae. The package ‘Generic Linux kernel image’ needs not be removed because it is just a meta-package to pull in the latest kernel image.
  4. Ubuntu Software CenterThen, under installed software, search for linux-headers.
  5. Do the same as step 3. Remove previous version of the linux headers.
  6. Remove GRUB entries for older kernels.

This post will describe on how to enable static and dynamic linking on gcc (GNU Compiler Collection).

By default, a library is dynamically linked, if the -l option is used to include the library.

For example, the code below will dynamically link somelib as well as libc, libstdc++, etc.

g++ file.cpp -o a.out -l somelib

Meanwhile, if the -static specifier is used, all libraries will be linked statically.

g++ file.cpp -o a.out -l somelib -static

Mixing between linking static and dynamic libraries is also possible; and there are two ways.

  1. Specify the full name of the static lib.
    • For example:

       g++ file.cpp -o a.out libsome.a -lsomelib2

    • By this way, the library libsome.a will be linked statically along with other object files. Meanwhile, somelib2 and the standard c libraries will remain dynamic.
  2. Pass additional options on to the linker.
    • The -Wl,<options> switch is used to pass on the options to the linker.
    • For example:

       g++ file.cpp -o a.out -Wl,-Bstatic -lsome -Wl,-Bdynamic -lsomelib2

    • The command above performs the same linking as method 1, as the -Wl,-Bstatic switch sets the linker in static-linking mode, and the -Wl,-Bdynamic switch sets the linker back to dynamic-linking mode.

Linking between static and shared library is just as simple as this. Hope this tutorial might help anyone encountering this problem.

Udacity Certificates

Posted: April 25, 2012 in Fun Stuff
Tags: ,

Received my first two certificates from Udacity online course.

Join Udacity today and enjoy the revolution in online learning.

It is amazing that after so maany years linux being actively developed, the buffer overflow exploit remains one of the top security vulnerabilities in 2011. Buffer overflow was first detailed in Smashing The Stack For Fun and Profit by Alphe One. Nevertheless, here is my first successful attempt in creating a buffer flow in my code.

The code is a simple one. Yet it forms the basis of a stack-based buffer overflow. Mystically, the program below prints a result of zero. The instruction ‘x = 1’ is skipped due to the buffer overflow exploit.

void function(int a, int b, int c) {
    int *ret;
    ret = (int*) &amp;a - 1;
    (*ret) += 8;

void main() {
    int x;
    x = 0;
    x = 1;