JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
The value of errno is tested, but the last function call was not to a function that can set errno.
For this warning class, CodeSonar will treat a function as setting errno if it is specified using the ERRNO_SETTING_FUNCTIONS configuration parameter.
ERRNO_SETTING_FUNCTIONS += f
| Class Name | Inappropriate Test of Error Code | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||||||||
| Mnemonic | LANG.ERRCODE.ITEST | ||||||||||||||||||
| Categories |
|
||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Inappropriate Test of Error Code" |
#include <errno.h>
#include <stdio.h>
void noerrno(void){
/* errno is never set by noerrno() or any of its callees */
}
int test_ftell_errno(FILE *fp){
(void) ftell(fp);
if (errno !=0) { /* ok: last function call was to ftell(), which can set errno */
return 1;
}
return 0;
}
int test_noerrno_errno(void){
noerrno();
if (errno != 0) { /* 'Inappropriate Test of Error Code' warning issued here
* - last function call was to noerrno(), which never sets errno
*/
return 1;
}
return 0;
}
int test_errno_path(FILE *fp, int i){
if (i > 0){
(void) ftell(fp);
}
else {
noerrno();
}
if (errno != 0){ /* 'Inappropriate Test of Error Code' warning issued here
* - on paths where i<=0 the last function call was to noerrno(), which never sets errno
*/
return 1;
}
return 0;
}
The following configuration file parameters affect checks for this warning class.