danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
699 stars 158 forks source link

New CWE in master after code modifications #422

Closed AndreyAlifanov closed 1 year ago

AndreyAlifanov commented 1 year ago

Hi!

PVS-Studio found another CWE in "fixed" code.

source.hpp, line 172 [CWE-191] V555: The expression '(length - len) > 0' will work as 'length != len'.

The analyzer detected a potential error in an expression of "A - B > 0" type. It is highly probable that the condition is wrong if the "A - B" subexpression has the unsigned type.

The "A - B > 0" condition holds in all the cases when 'A' is not equal to 'B'. It means that we may write the "A != B" expression instead of "A - B > 0". However, the programmer must have intended to implement quite a different thing
danielaparker commented 1 year ago

Fixed on master. Noting that the original '(length - len) > 0', equivalent to 'length != len', works correctively, even if not what the author (me) intended.