Examples of errors detected by the V555 diagnostic
V555. Expression of the 'A - B > 0' kind will work as 'A != B'.
PHP:Hypertext Preprocessor
V555 The expression of the 'A - B > 0' kind will work as 'A != B'. ZendAccelerator.c 3915
typedef union _znode_op { uint32_t num; .... } struct _zend_op { _znode_op op2; .... } struct _zend_op_array { uint32_t num_dynamic_func_defs; .... } typedef struct _zend_op_array zend_op_array; static void preload_remove_declares(zend_op_array *op_array) { zend_op *opline = op_array->opcodes; .... while (opline != end) { switch (opline->opcode) { .... case ZEND_DECLARE_FUNCTION: .... if (func && func == op_array->dynamic_func_defs[opline->op2.num]) { .... if (op_array->num_dynamic_func_defs == 0) { dynamic_func_defs = NULL; } else { .... if (op_array->num_dynamic_func_defs - opline->op2.num > 0) { // <= memcpy( dynamic_func_defs + opline->op2.num, op_array->dynamic_func_defs + (opline->op2.num + 1), sizeof(zend_op_array*) * (op_array->num_dynamic_func_defs - opline->op2.num)); } // the rest of the code } It's a subtraction of two unsigned values. If the minuend is less than the subtrahend, the result will be a value less than zero. However, since there are unsigned values, we get the modulo arithmetic. This expression should be replaced with the following: 'if (op_array->num_dynamic_func_defs > opline->op2.num)'.
FreeSWITCH
V555 The expression 'parser->maxlen - parser->minlen > 0' will work as 'parser->maxlen != parser->minlen'. switch_ivr.c 2342
typedef uintptr_t switch_size_t; switch_size_t maxlen; switch_size_t buflen; switch_size_t minlen; SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(....) { .... if (parser->maxlen - parser->minlen > 0 && ....) { len = 0; } .... } K Desktop Environment
V555 The expression 'm_pos - backOffset > 0' will work as 'm_pos != backOffset'. pp-stream.cpp 225
unsigned int rpp::Stream::peekLastOutput(uint backOffset) const { if(m_pos - backOffset > 0) return m_string->at(m_pos - backOffset - 1); return 0; } Similar errors can be found in some other places:
- V555 The expression 'nextOffset - currentOffset > 0' will work as 'nextOffset != currentOffset'. pp-location.cpp 211
OpenJPEG
V555 The expression of the 'A - B > 0' kind will work as 'A != B'. itkopenjpeg j2k.c 3421
typedef struct opj_stepsize { OPJ_UINT32 expn; OPJ_UINT32 mant; }; bool j2k_read_SQcd_SQcc( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, OPJ_BYTE* p_header_data, OPJ_UINT32 * p_header_size, struct opj_event_mgr * p_manager ) { .... OPJ_UINT32 l_band_no; .... l_tccp->stepsizes[l_band_no].expn = ((l_tccp->stepsizes[0].expn) - ((l_band_no - 1) / 3) > 0) ? (l_tccp->stepsizes[0].expn) - ((l_band_no - 1) / 3) : 0; .... } PHP:Hypertext Preprocessor
V555 The expression 'out_buf_size - ocnt > 0' will work as 'out_buf_size != ocnt'. filters.c 1702
static int strfilter_convert_append_bucket( { size_t out_buf_size; .... size_t ocnt, icnt, tcnt; .... if (out_buf_size - ocnt > 0) { // <= .... php_stream_bucket_append(buckets_out, new_bucket TSRMLS_CC); } else { pefree(out_buf, persistent); } .... } Wine Is Not an Emulator
V555 The expression 'This->nStreams - nr > 0' will work as 'This->nStreams != nr'. editstream.c 172
static HRESULT AVIFILE_RemoveStream(IAVIEditStreamImpl* const This, DWORD nr) { .... This->nStreams--; if (This->nStreams - nr > 0) { // <= memmove(This->pStreams + nr, This->pStreams + nr + 1, (This->nStreams - nr) * sizeof(EditStreamTable)); } .... } Similar errors can be found in some other places:
- V555 The expression 'This->fInfo.dwStreams - nStream > 0' will work as 'This->fInfo.dwStreams != nStream'. avifile.c 469
OpenSSL
V555 The expression of the 'A - B > 0' kind will work as 'A != B'. bio_ok.c 243
typedef struct ok_struct { .... size_t buf_len_save; size_t buf_off_save; .... } BIO_OK_CTX; static int ok_read(BIO *b, char *out, int outl) { .... BIO_OK_CTX *ctx; .... /* copy start of the next block into proper place */ if(ctx->buf_len_save - ctx->buf_off_save > 0) .... } Scilab
V555 The expression 'wcslen(dir) - wcslen(DirTmp) > 0' will work as 'wcslen(dir) != wcslen(DirTmp)'. getscilabdirectory.c 44
size_t wcslen(const wchar_t * _Str); char *getScilabDirectory(BOOL UnixStyle) { .... if (wcslen(dir) - wcslen(DirTmp)>0) { dir[wcslen(dir) - wcslen(DirTmp)] = L'\0'; } else return NULL; .... } Similar errors can be found in some other places:
- V555 The expression 'nbcharacters - 1 > 0' will work as 'nbcharacters != 1'. checkcsvwriteformat.c 85
Trans-Proteomic Pipeline
V555 The expression 'ppw_ref.size() - have_cluster > 0' will work as 'ppw_ref.size() != have_cluster'. proteinprophet.cpp 6767
size_type size() const; void computeDegenWts() { .... int have_cluster = 0; .... if ( have_cluster > 0 && ppw_ref.size() - have_cluster > 0 ) .... }