Segmentation Fault

Common causes

Segmentation fault

A few causes of a segmentation fault can be summarized as follows:

  • attempting to execute a program that does not compile correctly. Note that most compilers will not output a binary given a compile-time error.
  • a buffer overflow.
  • using uninitialized pointers.
  • dereferencing NULL pointers.
  • attempting to access memory the program does not own.
  • attempting to alter memory the program does not own (storage violation).
  • exceeding the allowable stack size (possibly due to runaway recursion or an infinite loop)

Generally, segmentation faults occur because a pointer is NULL, or because it points to random memory (probably never initialized to anything), or because it points to memory that has been freed/deallocated/”deleted”.

e.g.

    char *p1 = NULL;           // Initialized to null, which is OK,
                               // (but cannot be dereferenced on many systems).
    char *p2;                  // Not initialized at all.
    char *p3  = new char[20];  // Great! it's allocated,
    delete [] p3;              // but now it isn't anymore.

Now, dereferencing any of these variables could cause a segmentation fault.

Shell script

Coz Perl failed…

#!/bin/sh

printUsage()
{
echo “Usage: $0 [-w] [-h]”
echo “Options:”
echo ” -w To specify working repository”
echo ” -k Display available options”
}

if [ $# -eq "0" ] # Script invoked with no command-line args?
then
printUsage
exit
fi

if [ ! -d $2 ]; then
echo “Working Repository $2 does not exist”
exit
fi

while true;do
case $1 in
-w)
echo “====== Working Repository is $2 =====”
shift
;;
-h)
printUsage
shift
;;
*)
echo “Option $1 not available”
printUsage
exit
;;
esac
shift
done

# iterate packages
for pkg in “$2″/cmapp/ng*rgr; do
echo “Current Directory is $pkg”
# skipping non-checked out directories
if [ -L $pkg ]; then
echo “$pkg SKIPPED”
continue;
fi
# skipping directories without edi folder
if [ ! -d $pkg/edi ]; then
echo “$pkg SKIPPED”
continue;
fi
# push directory
pushd $pkg/edi
# run ntt
ntt config && ntt loadbasedb && ntt boot
# skip when can’t start ntt for whatever reason
if [ "$?" -ne "0" ]; then continue; fi
# iterate directories
for msg in *; do
# skip non-directories
if [ ! -d $msg ]; then continue; fi
# skip directories not containing regressions
ls $msg/*.scn >/dev/null 2>&1
if [ "$?" -ne "0" ]; then continue; fi
# run regressions for folder
nice -20 ntt t $msg
done
# stop ntt
ntt vsy
# popping directory
popd
done

Perl script for running all regressions

while I go home and raid a few dragons or kill a few alliances…

#!/usr/bin/perl -w

use warnings;
use strict;
use Cwd;
use Getopt::Long;
use FindBin qw($Bin);

sub printCwd
{
my $pwd = getcwd;
print “Current directory is: $pwd\n”;
}

sub printUsage
{
printf “rgrAutoRun : [-w repository] [-h]\n”;
printf “\t-w, Specify the working repository\n”;
printf “\t-h, Print all the options\n”;
}

sub processArgs
{
my ($w, $h) = (”, 0);
GetOptions(
‘w=s’ => \$w,
‘h’ => \$h
);
$h and printUsage() and exit;
chomp($w);
return $w;
}

my $repository = processArgs;
chdir “$repository” or die “cannot cd to $repository: $!”;
`setpwe`;
chdir “cmapp” or die “cannot cd to $repository/cmapp: $!”;
print “#################### WORKING REPOSITORY $repository ####################\n”;
my @rgrDirs = glob(“ng*rgr”);

for my $rgrDir (@rgrDirs)
{
printCwd;
chdir “$Bin”;

printCwd;
chdir “$repository/cmapp” or die “cannot cd to $repository/cmapp: $!”;
my $result = 0;
print “===============***** STARTING ON $rgrDir *****===============\n”;
printCwd;
$result = chdir “$rgrDir” or warn “cannot cd to $rgrDir: $!”;
next if $result == 0;
$result = chdir “edi” or warn “cannot cd to $rgrDir/edi: $!”;
if ($result ==0)
{
chdir “../” or warn “cannot go back to $rgrDir: $!”;
next;
}
printCwd;
`ntt t ‘*/*.scn’`;
`ntt vsy`;
chdir “../..” or die “cannot cd to ../..: $!”;
printCwd;
print “===============***** FINISH WITH $rgrDir *****===============\n”;
}

Something new everyday for a C++ noob

(a || b ) && c ) = c && ( a || b ); Perhaps not so obvious, but the C++ standard requires lazy evaluation. In this case, whenever c happens to be false, in the first case ( a || b ) has to be evaluated, whereas in the second case, it can be skipped as the entire expression can never evaluate to true anymore.

New Putty Look

My new putty look, much easier on my poor eyes…
  • Default Foreground: 255/255/255
  • Default Background: 45/45/45
  • ANSI Black: 77/77/77
  • ANSI Green: 152/251/152
  • ANSI Yellow: 240/230/140
  • ANSI Blue: 205/133/63
  • ANSI Blue Bold 135/206/235
  • ANSI Magenta: 255/222/173
  • ANSI Cyan: 255/160/160
  • ANSI Cyan Bold: 255/215/0
  • ANSI White: 245/222/179

PuTTY Settings

Session

Host Name: sydlnx03
Port: 22
Connection type: SSH

Terminal > Keyboard

The Backspace key: Control-H

Window

Rows: 60
Lines of scrollback: 10000

Windows > Appearance

Cursor appearance: Block
Font settings: Consolas, 10-point
Font quality: ClearType

Window > Colours

ANSI Blue: R74; G74; B255
ANSI Blue Bold: R140; G140; B255

Conection>SSH>X11

X11 forwarding: Enable
X display location: localhost: 0.0
Remote X11 authentication protocol: MIT-Magic-Cookie-1

Flight Create Links

http://ngdwiki.lon.amadeus.net/wiki/index.php/Creating_a_Flight

http://ngdwiki.lon.amadeus.net/wiki/index.php/FLT:Flight_create_troubleshooting_guide

http://ngdwiki.lon.amadeus.net/wiki/index.php/How-to’s#Create_the_booking

http://ngdwiki.lon.amadeus.net/wiki/index.php/FLT:Flight_disruption_troubleshooting_guide

http://ngdwiki.lon.amadeus.net/wiki/index.php/CM:FLT:Disruption_Product

http://lonjfe1a.lon.amadeus.net/JFE_FM/FMFlightTechnicalData/

http://gcnet.nce.amadeus.net/DSP/OBE/Test/Log/logviewer/

Useful Vim Settings

General Indentation Settings

:set autoindent
If set, Vim automatically indents a new line to the same indentation used by previous line. In other words ViM automatically tabs a new line. smartindent and cindent are autoindent variations and changes the way indentation and formatting more precisely.

:set smartindent
Context-sensitive autoindent, great when coding, makes intendation aware of C-like syntax.

:set shiftwidth
Using this option you can define number of spaces placed on every indentation step i.e. :set shiftwidth=3 will instruct Vim to indent with 3 spaces for every TAB command.

TAB Settings

:set expandtab
Use this option if you want every TAB to be expanded to spaces.

:set smarttab
If this option is set, then TAB command shifts line to right and BACKSPACE shifts line to left, both inserting number of blanks as defined in shiftwidth. If smarttab is not set, then TAB inserts blanks according to tabstop.

:set softtabstop
This one tells Vim to interpret TAB as an indent command instead of insert-a-TAB command.

:set tabstop
Simply, it instructs Vim how many space characters Vim counts for every TAB command. According to Vim manual it’s recommended to leave default tabstop=8, what means every TAB is displayed with 8 space characters, and adjust only softtabstop and shiftwidth.

C-style Indent

:set cindent
This sets autoindent to even more smart and strict mode for C and C++ source code.

:set cinoptions
Simply, it sets cindent configuration options.

My .vimrc file:

syntax on “turn on syntax highlighting
set backgound=dark “set background to dark
set expandtab “convert all tabs to white spaces
set softtabstop=2 “tab size
set mouse=a “use mouse everywhere
set laststatus=2 “always show the status line
set incsearch “do highlight as you type your search phrase
set matchtime=5 “5 tenths of a second to blink matching bracket
set statusline=%F%m%r%h%w[%L]%y[%p%%][%04l,%04v] “full path of file, modified/readonly/help/preview flags, current file format, syntax, %, line, column
 

Games we played together

  • Diablo 1
  • Diablo 2
  • Titan Quest
  • Final Fantasy 7
  • Final Fantasy 8
  • Final Fantasy 9
  • Final Fantasy 10
  • Age of Empires 2
  • Age of Empires 3
  • Civilization 4
  • Civilization Colonization
  • 三國無雙
  • 三國志 9
  • 三國志 10
  • 三國志 11
  • 信長之野望
  • 太閣立志傳 4
  • 太閣立志傳 5
  • 大航海時代
  • 軒轅劍 天之痕
  • 軒轅劍 3
  • 仙劍奇俠傳
  • World of Warcraft

Red Wine Beef Stew

  • Ox tails x 2
  • Red wine x 1 bottle
  • Beef stock 300-400ml
  • Celery x 2 pieces (cut into 5cm long pieces)
  • Onions x 2 (cut into large pieces)
  • Carrots x 3 (cut into large pieces)
  • Bacon 300g
  • Bay Leaves x 2
  • Some whole black pepper, salt, and tomato sauce
  1. Ox tail沾點麵粉下鍋稍微煎一下,撈起備用。
  2. 煎bacon,出油後加入carrots, celery and onions 炒到洋蔥變軟。
  3. 加入煎好的ox tail, red wine, beef stock, bay leaves, black pepper, salt and tomato sauce。用大火不加蓋煮到沸騰,轉小火煮至軟爛。
  4. 放隔夜,用點大蒜炒broccoli, mushrooms, flat beans,把beef stew的油撈掉後再跟蔬菜一起加熱。