// functionality removed for clarity // this 'logic' will always fail to write 'iSize' bytes of data // why? void write_data(void* pData, size_t iSize) { int fd = 0; // // open file for writing and set 'fd' // size_t dwOffset = 0; if( (_lseek(fd, static_cast(dwOffset), SEEK_SET) < 0) || (_write(fd, pData, static_cast (iSize) < 0) ) ) { // we get here if _lseek returns an error (e.g. -1) // or if we fail to write 'iSize' bytes of 'pData' to a file } }
When we ran PC-Lint on the above source code we found the following warnings:
Warning 685: Relational operator '<' always evaluates to 'false' Warning 568: non-negative quantity is never less than zero
Why don't more developers and/or software companies use PC-Lint? It should be standard practice to remove warning and errors from source code before building, testing and releasing, yet it has been our experience that few companies use static analysis before running unit tests and before releasing builds.
No comments:
Post a Comment