Monday, November 08, 2004

KNU: Check for the following conditions

Accessing or deleting memory you do not own
1. Dereferencing a NULL pointer
a. *(NULL)
b. NULL->member
c. NULL[1]
d. NULL->function()
e. strcpy( NULL, "hello" )
f. *(NULL)(params);
g. this == NULL during an implicit (*this).
2. Dereferencing an uninitialized pointer
a. blah* pPointer; *pPointer
b. All same cases as (1)
3. Dereferencing a deleted pointer
a. delete pPointer; *pPointer
b. All same cases as (1)
4. Deleting an uninitialized pointer
a. blah* pPointer; delete pPointer;
5. Deleting a pointer twice
a. delete pPointer; delete pPointer;
6. Deleting non-dynamic memory
a. int x; int* p = &x; delete p;
http://devcentral.iftech.com/articles/C++/nocrashes/ (1 of 4) [3/15/2002 6:17:17 PM]
DevCentral - Writing Crash-Proof C/C++ Code
7. Writing beyond the bounds of an array
a. int x[10]; x[-1] = 1;
b. int x[10]; x[10] = 1;
c. (a) and (b) but hidden in loops
Uncaught exceptions
1. Divide by zero
a. int x = 0; 2/x
b. double x = 0.0; 2.0/x
c. int x = 0; 2%x
d. You will also see overflow and underflow occasionally
2. Stack overflow
a. Infinitely recursive function
void InfiniteRecurse( int x )
{
if ( false )
{
// terminating condition which is never met
return;
}
else
{
// recurse condition which is always met
InifiniteRecurse(x+1);
}
}
b. Infinitely recursive set of functions
Same as (a) but a set of functions are mutually recursive, so the call stack looks like a -> b -> c -
> a -> b -> c -> a -> b -> c -> a -> b -> c -> ...
c. Valid recursive function but each call using too much stack space
void BigRecurse( unsigned int x )
{
int aBigArray[1000];
if( x >= 1000 )
{
return;
}
else
{
aBigArray[x] = x;
BigRecurse(x+1);
}
}
3. Out of memory; this may show up as an exception on some systems, others will just return NULL from
the new or malloc (Visual C++'s C library returns NULL and does not throw an exception).
a. int* p = new int;
4. User or library code generated exceptions that failed to get wrapped in a try/catch. Third party code may
throw exceptions under some circumstances. Your code might intentionally throw exceptions. If these
miss getting caught then the exceptions will make it all the way to the top of the thread.
a. ret = ThisFunctionThrowsAnException();

Friday, November 05, 2004

KNU - relational operators

=, >, <, && (and), || (or), ! (not)
=> (implies)
forall, there exists, max, min (operators to be decided)
precondition: [ 0 <= x <= 9]
postcondition: [ 0 <= x <= 9, y^2 = x ]
short x = {2,4,5,>76};

unused operators:
~,!,@,#,$,^

Thursday, November 04, 2004

fundamental mental block in the way we do programming

Take a typical software thats being developed, most of them are to do with data structures how to sync them up, how to efficiently sort them up, query them, convert them from one form to another (transform). Not all of them needs handcoding from scratch, but eventually thats what is happening all over. Why there is no visual basic(that solved efficiently the 80% GUI issue) to solve this ????? Its time for visual C??? Probably the key take for such a system is to reverse engineer the existing tons of code?

Wednesday, November 03, 2004

web'ed home

Music system is wireless, where the music is served from an online storage which can be accessed anywhere one goes
Food packaging comes in RFID, so the fridge would know which is expired and what is less and can be integrated with inventory of home
One gadget that behaves as mouse, remote, cordless phone, cellphone, pda, camera & music player

Tuesday, November 02, 2004

personal hard disk

personal storage is going to revolutionize the industry

-- personal storage of TB's (PMEM)
-- wireless capabilities (secure) so it can interact with plethora of personal devices like

  • PDA
  • MP3 player
  • Cellphone
  • Camera (oh by the way, soon my shades are going to be my camera lens and it is connected (wireless) to my PMEM, and can record whatever I can see, whenever i want to record, also my shades are going to be my video screens where i can play games, i can view movies, where i can do my job, my movie theater, my personal world (MPW)

gadgets galore

some day soon, ipod is going to carry a camera, PDA & cell phone capabilities built in and atleast one needn't carry multiple gadgets for multiple purposes