Examples of errors detected by the V503 diagnostic
V503. Nonsensical comparison: pointer < 0.
Xpdf
V503 This is a nonsensical comparison: pointer < 0. pdf2swf q.c 804
char* stringarray_at(stringarray_t*sa, int pos)
{
stringarray_internal_t*s =
(stringarray_internal_t*)sa->internal;
char *p;
if (pos<0 || pos>=s->num)
return 0;
p = *(char**)&s->pos.buffer[pos*sizeof(char*)];
if(p<0) // <=
return 0;
return p;
}
IPP Samples
V503 This is a nonsensical comparison: pointer < 0. ipprsample ippr_sample.cpp 501
void lNormalizeVector_32f_P3IM(Ipp32f *vec[3],
Ipp32s* mask, Ipp32s len)
{
Ipp32s i;
Ipp32f norm;
for(i=0; i<len; i++) {
if(mask<0) continue;
norm = 1.0f/sqrt(vec[0][i]*vec[0][i]+
vec[1][i]*vec[1][i]+
vec[2][i]*vec[2][i]);
vec[0][i] *= norm; vec[1][i] *= norm; vec[2][i] *= norm;
}
}
This is what should have been written here: if(mask[i]<0) continue;
Chromium
V503 This is a nonsensical comparison: pointer < 0. browser profile_impl.cc 169
void GetCacheParameters(ContextType type, FilePath* cache_path,
int* max_size) {
....
*max_size = 0;
if (!base::StringToInt(value, max_size)) {
*max_size = 0;
} else if (max_size < 0) {
*max_size = 0;
}
....
}
Chromium
V503 This is a nonsensical comparison: pointer < 0. platform_file_win.cc 124
typedef void *HANDLE;
#if defined(OS_WIN)
typedef HANDLE PlatformFile;
#elif defined(OS_POSIX)
typedef int PlatformFile;
#endif
int64 SeekPlatformFile(PlatformFile file,
PlatformFileWhence whence,
int64 offset) {
base::ThreadRestrictions::AssertIOAllowed();
if (file < 0 || offset < 0)
return -1;
LARGE_INTEGER distance, res;
distance.QuadPart = offset;
DWORD move_method = static_cast<DWORD>(whence);
if (!SetFilePointerEx(file, distance, &res, move_method))
return -1;
return res.QuadPart;
}
Scilab
V503 This is a nonsensical comparison: pointer < 0. scicos.c 5826
int write_xml_states(....)
{
....
FILE *fd = NULL;
....
wcfopen(fd, (char*)xmlfile, "wb");
if (fd < 0)
{
sciprint(_("Error: cannot write to '%s' \n"), xmlfile);
....
}
OGDF
V503 This is a nonsensical comparison: pointer <= 0. sugiyama.cpp 571
int Hierarchy::calculateCrossingsPlaneSweep(int i)
{
const Level *pLevel[2];
pLevel[0] = m_pLevel[i]; pLevel[1] = m_pLevel[i+1];
if (pLevel[0]->high() <= 0 || pLevel[1] <= 0) return 0;
....
}
Asterisk
V503 This is a nonsensical comparison: pointer < 0. parking_manager.c 520
static int manager_park(....)
{
....
const char *timeout = astman_get_header(m, "Timeout");
....
int timeout_override = -1;
....
if (sscanf(timeout, "%30d", &timeout_override) != 1 ||
timeout < 0) { // <=
astman_send_error(s, m, "Invalid Timeout value.");
return 0;
}
}
.NET CoreCLR
V503 This is a nonsensical comparison: pointer >= 0. cee_wks gc.cpp 21707
void gc_heap::make_free_list_in_brick (BYTE* tree,
make_free_args* args)
{
assert ((tree >= 0));
....
}
Similar errors can be found in some other places:
- V503 This is a nonsensical comparison: pointer >= 0. cee_wks gc.cpp 23204
- V503 This is a nonsensical comparison: pointer >= 0. cee_wks gc.cpp 27683
Haiku Operation System
V503 This is a nonsensical comparison: pointer <= 0. Header.cpp 900
extern
char *strstr(const char *string, const char *searchString);
void
TTextControl::MessageReceived(BMessage *msg)
{
....
while (node.GetNextAttrName(buffer) == B_OK) {
if (strstr(buffer, "email") <= 0)
continue;
....
}
GINV
V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 477
class IMonom {
....
const IVariables* depend();
}
std::ostream& operator<<(std::ostream& out, const IMonom& a) {
switch(a.monomInterface()->systemType()->type()) {
....
case ISystemType::DifferentialEquation: {
IASSERT(a.depend() != NULL);
if (a.degree() == 0)
if (a.depend() < 0)
{
}
....
}
}
}
Similar errors can be found in some other places:
- V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 482
- V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 504
- V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 509
- And 3 additional diagnostic messages.
FreeBSD Kernel
V503 This is a nonsensical comparison: pointer >= 0. geom_vinum_plex.c 173
static int
gv_plex_offset(...., int *sdno, int growing)
{
....
*sdno = stripeno % sdcount;
....
KASSERT(sdno >= 0, ("gv_plex_offset: sdno < 0"));
....
}
Similar errors can be found in some other places:
- V503 This is a nonsensical comparison: pointer >= 0. geom_vinum_raid5.c 602
- V503 This is a nonsensical comparison: pointer >= 0. geom_vinum_raid5.c 610
OpenToonz
V503 This is a nonsensical comparison: pointer < 0. styleselection.cpp 104
bool pasteStylesDataWithoutUndo(....)
{
....
if (palette->getStylePage(styleId) < 0) { // <=
// styleId non e' utilizzato: uso quello
// (cut/paste utilizzato per spostare stili)
palette->setStyle(styleId, style);
} else {
// styleId e' gia' utilizzato. ne devo prendere un altro
styleId = palette->getFirstUnpagedStyle();
if (styleId >= 0)
palette->setStyle(styleId, style);
else
styleId = palette->addStyle(style);
}
....
}
The getStylePage() function returns a pointer to some page: TPalette::Page*.
Far2l
V503 This is a nonsensical comparison: pointer <= 0. fstd_exSCPY.cpp 8
char *WINAPI StrCpy(char *dest, LPCSTR src, int dest_sz)
{
if(dest <= 0)
return NULL;
....
}
Tizen
V503 This is a nonsensical comparison: pointer < 0. apps_view_circle_indicator.c 193
static void __page_focus_changed_cb(void *data)
{
int i = 0;
int *focus_unit = (int *)data;
if (focus_unit == NULL || focus_unit < 0) {
_E("focus page is wrong");
return ;
}
....
}
This is what should have been written here: if (focus_unit == NULL || *focus_unit < 0)
Tizen
V503 This is a nonsensical comparison: pointer < 0. apps_view_circle_indicator.c 219
static void __page_count_changed_cb(void *data)
{
int i = 0;
int *page_cnt = (int *)data;
if (page_cnt == NULL || page_cnt < 0) {
_E("page count is wrong");
return ;
}
....
}
This is what should have been written here: if (page_cnt == NULL || *page_cnt < 0)
LLVM/Clang
V503 [CWE-697, CERT-EXP08-C] This is a nonsensical comparison: pointer < 0. isl_coalesce.c 3181
struct isl_coalesce_info {
isl_basic_map *bmap;
....
};
static isl_stat tab_insert_divs(struct isl_coalesce_info *info, ....)
{
....
if (any) {
if (isl_tab_rollback(info->tab, snap) < 0)
return isl_stat_error;
info->bmap = isl_basic_map_cow(info->bmap);
info->bmap = isl_basic_map_free_inequality(info->bmap, 2 * n);
if (info->bmap < 0)
return isl_stat_error;
return fix_constant_divs(info, n, expanded);
}
....
}
LLVM/Clang
V503 This is a nonsensical comparison: pointer < 0. isl_local_space.c 257
isl_size isl_local_space_var_offset(__isl_keep isl_local_space *ls,
enum isl_dim_type type)
{
isl_space *space;
space = isl_local_space_peek_space(ls);
if (space < 0)
return isl_size_error;
....
}