Showing posts with label Article. Show all posts
Showing posts with label Article. Show all posts

28 July 2008

Don't forget about Lint

The lint utility that is supplied with Sun Studio 12 has some great features for analysing and diagnosing source code problems. Lint is a static source code analyser, but has large fallen out of fashion due to developers relying on compiler diagnostics.

Indeed, having your source run on a variety of UNIX platforms is a great way to uncover issues. I regularly have to compile the same code on Solaris, RedHat AS 5, Ubuntu, Debian, HP-UX, HP-UX Itanium & AIX.

The various compilers do have excellent warnings and that's worth exploring as a project, some of them have great 64-bit checking options.

Sun Studio Lint has some wonderful options for diving into your source code to do that extra thorough analysis. It can uncover 64-bit porting problems and something I didn't know, was that it can try to find security problems also.

Example output:

(34) warning: possible ptrdiff_t overflow
(242) warning: format argument to sprintf() contains an unbounded string specifier
(252) warning: format argument to sprintf() contains an unbounded string specifier
(319) warning: possible ptrdiff_t overflow
(324) warning: possible ptrdiff_t overflow

So it can detect the following potential problem :
"Use the -errsecurity option to check your code for security loopholes."

char buffer[80];

sprintf( buffer, sizeof(buffer)-1, "%c%d%d%s%d", ch, i1, i2, filename, i3 );


where it's saying that the filename string isn't limited and could overrun the buffer. One fix would be to change to use "%.*s" rather than "%s".

Sun Studio docs for Lint

08 February 2007

Intel Article on multithreaded programming

Intel: Nuts and Bolts of Multithreaded Programming

Get the basics about parallel algorithms, parallel programming APIs, and the tools required to start writing your own parallel programs.