èªè ã¯ããThe Last Lineã®å¹æããšããã¿ã€ãã«ã®ç§ã®èšäºãèŠããŠãããããããŸããã ããã¯ãç§ãæ°ä»ãããã¿ãŒã³ãæããŸããã»ãšãã©ã®å Žåãåãã¿ã€ãã®ããã¹ããããã¯ã®æåŸã®è¡ã«ééãããããŸãã ããã§ãæ°ããèå³æ·±ã芳å¯ã«ã€ããŠã話ããããšæããŸãã ããã°ã©ããŒã¯ã2ã€ã®ãªããžã§ã¯ããæ¯èŒããæ©èœã«ééããç¯ããã¡ã§ãã ãã®ãããªå£°æã¯ä¿¡ããããããã«æããŸãããèªè ã«è¡æãäžãããšã©ãŒã®èšå€§ãªæ°ã®äŸã瀺ããŸãã æ°ããç 究ãèªãã§ãã ãããããã¯é¢çœããŠæãã§ãããã
çºè¡
ããã°ã©ãã¯ã2ã€ã®ãªããžã§ã¯ããæ¯èŒããããã«èšèšãããéåžžã«åçŽãªé¢æ°ã§ãã¹ãç¯ãããšãéåžžã«å€ããšäž»åŒµããŸãã ãã®ã¹ããŒãã¡ã³ãã¯ãCãC ++ãããã³CïŒã§éãããå€æ°ã®ãããžã§ã¯ãããã§ãã¯ããããŒã ã®çµéšã«åºã¥ããŠããŸãã
åé¡ã®é¢æ°ã¯ã IsEqual ã Equals ã Compare ã AreEqualãªã©ãšåŒã°ããŸãã ãŸãã¯== ,! =ãªã©ã®ãªãŒããŒããŒãæŒç®åã
èšäºãæžããŠãããšãã«ãæ¯èŒé¢æ°ã«é¢é£ãããšã©ãŒã«ééããããšããããããŸãã ãã®åé¡ããã詳现ã«èª¿æ»ããããšã«ããçºèŠãããšã©ãŒã®ããŒã¿ããŒã¹ã調æ»ããŸããã ãããè¡ãããã«ãããŒã¿ããŒã¹ã§Cmp ã Equal ã Compareãªã©ã®åèªãå«ãååã®é¢æ°ãæ€çŽ¢ãããŸããã çµæã¯éåžžã«å°è±¡çã§è¡æçã§ããã
äžè¬ã«ããã®ã¹ããŒãªãŒã¯ãThe Last Lineã®å¹æããšããèšäºãæžãããšã«äŒŒãŠããŸãã åæ§ã«ãç§ã¯ç°åžžã«æ°ã¥ããããããã詳现ã«ç 究ããããšã«ããŸããã æ®å¿µãªãããèšåãããèšäºãšã¯ç°ãªããç§ã¯ã©ã®ãããªæ°åãçµ±èšãæã£ãŠããã¹ããããããŸããã ãããããã©ã®ããã«ãäœãèšç®ã§ããã-åŸã§èããŸãã ä»ãç§ã¯çŽèŠ³ã«å°ãããç§ã®æ°æã¡ãå ±æããããšãã§ããã ãã§ãã 圌ãã¯ãæ¯èŒé¢æ°ã«å€ãã®ãšã©ãŒããããšèšããŸãããããŠãç§ãå€æ°ã®å°è±¡çãªäŸã瀺ããšããããªãã¯åãæèŠãæã£ãŠãããšç¢ºä¿¡ããŠããŸãã
å¿çåŠ
æåŸã®ã©ã€ã³ãšãã§ã¯ãã«æ»ããŸãããã ã¡ãªã¿ã«ãããããªãããããèªãã§ããªãã®ãªããäžæåæ¢ããŠåœŒå¥³ãšç¥ãåãããšããå§ãããŸãã ãã®ãããã¯ã®ãã詳现ãªåæããããŸãïŒã æåŸã®è¡ã®å¹æã®èª¬æ ãã
äžè¬ã«ãæåŸã®è¡ã®ãšã©ãŒã®åå ã¯ãéçºè ãçŸåšã®ãã©ã°ã¡ã³ãã®å®äºã«éäžããã®ã§ã¯ãªãã次ã®è¡/ã¿ã¹ã¯ã«ãã§ã«å¿ãåãããŠãããšããäºå®ã«ãããšçµè«ä»ããããšãã§ããŸãã ãã®çµæãåãã¿ã€ãã®ããã¹ããããã¯ãæåŸã«æžããæåŸã«ã圌ã¯ä»¥åã®ãã®ãããã¿ã€ããã¹ãããå¯èœæ§ãé«ããªããŸãã
æ¯èŒé¢æ°ãæžããšããéçºè ã¯ãããäºçŽ°ã§ãããšèããŠãããã«çŠç¹ãåãããªãããšãå€ããšæããŸãã èšãæããã°ã圌ã¯ãããèããã«èªåçã«ã³ãŒããæžããŸãã ãã以å€ã®å Žåãåæ§ã®ãšã©ãŒãäœæããæ¹æ³ã¯æ確ã§ã¯ãããŸããã
bool IsLuidsEqual(LUID luid1, LUID luid2) { return (luid1.LowPart == luid2.LowPart) && (luid2.HighPart == luid2.HighPart); }
PVS-Studioã¢ãã©ã€ã¶ãŒã¯ã RunAsAdmin Explorer Shim ïŒC ++ïŒãããžã§ã¯ãã³ãŒãã§ãã®ãšã©ãŒãæ€åºããŸããïŒ V501 '=='æŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒluid2.HighPart == luid2.HighPart RAACommon raacommonfuncsã cpp 1511
ã¿ã€ããã¹ã 2è¡ç®ã¯ã luid1.HighPart == luid2.HighPartã«ãªã£ãŠããã¯ãã§ãã
åæããŠãã³ãŒãã¯ç°¡åã§ãã ã©ããããã³ãŒãã®åçŽãã¯ãã¹ãŠãå°ç¡ãã«ããŸãã ããã°ã©ããŒã¯ããã®ãããªé¢æ°æšæºãäœæããŠãé¢çœããªãã¿ã¹ã¯ãããã«èªèããŸãã 圌ã¯å³åº§ã«é ã®äžã§é¢æ°ã®æžãæ¹ã決å®ããã³ãŒããå®è£ ããã ãã§ãã ããã¯ã«ãŒãã³ã§ãããæ®å¿µãªãããããéèŠã§è€éã§èå³æ·±ãã³ãŒãã®äœæã«é²ãããã«å¿ èŠãªããã»ã¹ã§ãã éçºè ã®èãã¯ãã§ã«ããã«ããããã®çµæã圌ã¯ééããç¯ããŸãã
ããã«ãããã°ã©ããŒããã®ãããªæ©èœã®åäœãã¹ããäœæããããšã¯ã»ãšãã©ãããŸããã ç¹°ãè¿ããŸããããããã®é¢æ°ã®èŠããäžã®åçŽãã¯å€±æããŸãã ãããã®é¢æ°ã¯éåžžã«åçŽã§åãã¿ã€ãã§ããããããããããã¹ãããã®ã¯åé·ãªããã§ãã 人ã¯èªåã®ç掻ã®äžã§äœçŸãã®ãã®ãããªæ©èœãæžãããã圌ã¯æ¬åœã«æ¬¡ã®æ©èœã§ééããç¯ãããšãã§ããã®ãïŒïŒ ãã¶ãããã§ãã
åæã«ããã®èšäºã¯ããã°ã©ãã³ã°ãåŠã¶åŠçã®ã³ãŒãã«é¢ãããã®ã§ã¯ãªããšããäºå®ã«æ³šæãåèµ·ããããšæããŸãã GCCãQtãGDBãLibreOfficeãUnreal Engine 4ãCryEngine VãChromiumãMongoDBãOracle VM Virtual BoxãFreeBSDãWinMergeãCoreCLRãMySQLãMonoãCoreFXãRoslynãMSBuildãªã©ã®ãããžã§ã¯ãã®ã³ãŒãã®ãšã©ãŒã«ã€ããŠè©±ããŠãããªã© ãã¹ãŠãéåžžã«æ·±å»ã§ãã
ç§ã¯ããªããå¯ãã®ãæãã»ã©å€ãã®å€æ§ãªäŸã瀺ããŸãã
æ¯èŒé¢æ°ã®èª€ã£ããã¿ãŒã³
æ¯èŒé¢æ°ã®ãã¹ãŠã®ãšã©ãŒã¯ãããã€ãã®ãã¿ãŒã³ã«åå²ãããŸãã ãã®èšäºã§ã¯ãCãC ++ãCïŒèšèªã®ãããžã§ã¯ãã®ãšã©ãŒãæ±ããŸãããå€ãã®ãã¿ãŒã³ã¯ç°ãªãèšèªã§åãã§ããããããããã®èšèªãäœããã®åœ¢ã§åããæå³ã¯ãããŸããã
ãã¿ãŒã³ïŒA <BãB> A
å€ãã®å Žåãæ¯èŒé¢æ°ã§ã¯æ¬¡ã®ãã§ãã¯ãå®è¡ããå¿ èŠããããŸãã
- A <b
- A> B
ããã°ã©ããŒã¯ãåã<operatorã䜿çšããŠå€æ°åã亀æããæ¹ãããçŸãããšæããå ŽåããããŸãã
- A <b
- B <a
ãã ããäžæ³šæã®ããã次ã®ãã§ãã¯ãååŸãããŸãã
- A <b
- B> a
å®éãåãæ¯èŒãããã§2åå®è¡ãããŸãã ããããããªãã¯è°è«ãããŠããããšãç解ããŠããªãã£ããããããŸããããå®éã®äŸã«ç§»ãããã¹ãŠãæããã«ãªããŸãã
string _server; .... bool operator<( const ServerAndQuery& other ) const { if ( ! _orderObject.isEmpty() ) return _orderObject.woCompare( other._orderObject ) < 0; if ( _server < other._server ) return true; if ( other._server > _server ) return false; return _extra.woCompare( other._extra ) < 0; }
PVS-Studioã¢ãã©ã€ã¶ãŒã¯ã MongoDB ïŒC ++ïŒãããžã§ã¯ãã³ãŒãã§ãã®ãšã©ãŒãæ€åºããŸããïŒ V581äºãã«äžŠãã§ãããifãæŒç®åã®æ¡ä»¶åŒã¯åäžã§ãã ãã§ãã¯è¡ïŒ44ã46ãparallel.h 46
ãã®ç¶æ ã¯æ¬¡ã®ãšããã§ãã
if ( other._server > _server )
äžèšã®2è¡ãšãŸã£ããåããã§ãã¯ãå®è¡ããããããåžžã«falseã«ãªããŸãã ã³ãŒãã®æ£ããããŒãžã§ã³ïŒ
if ( _server < other._server ) return true; if ( other._server < _server ) return false;
ãã®ãšã©ãŒã¯Chromiumãããžã§ã¯ãã³ãŒãïŒC ++ïŒã«ããããŸãã
enum ContentSettingsType; struct EntryMapKey { ContentSettingsType content_type; ... }; bool OriginIdentifierValueMap::EntryMapKey::operator<( const OriginIdentifierValueMap::EntryMapKey& other) const { if (content_type < other.content_type) return true; else if (other.content_type > content_type) return false; return (resource_identifier < other.resource_identifier); }
PVS-Studio èŠå ïŒ V517 ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸããã è«çãšã©ãŒãååšããå¯èœæ§ããããŸãã 61ã63è¡ç®ã確èªããŸããbrowser content_settings_origin_identifier_value_map.cc 61
C ++ã§äŸã瀺ããŸããããä»åºŠã¯CïŒã®çªã§ã IronPythonããã³IronRuby ïŒCïŒïŒã³ãŒãã§æ¬¡ã®ãšã©ãŒãèŠã€ãããŸããã
public static int Compare(SourceLocation left, SourceLocation right) { if (left < right) return -1; if (right > left) return 1; return 0; }
PVS-StudioèŠåïŒCïŒïŒïŒ V3021åäžã®æ¡ä»¶åŒãæã€2ã€ã®ãifãã¹ããŒãã¡ã³ãããããŸãã æåã®ãifãã¹ããŒãã¡ã³ãã«ã¯ã¡ãœããã®æ»ãå€ãå«ãŸããŸãã ããã¯ã2çªç®ã®ãifãã¹ããŒãã¡ã³ããç¡æå³ã§ããããšãæå³ããŸãã SourceLocation.cs 156
ããã§ã®èª¬æã¯äžèŠã ãšæããŸãã
ã泚æ CïŒã®ãšã©ãŒã®äŸã¯1ã€ãããããŸããããC ++ã®ãšã©ãŒã¯2ã€ãããŸããã ãã ããCïŒã®æ¹ããã£ãšå®å šã§ãããšããçµè«ã«æ¥ãããšã¯ãå§ãããŸããã å®éãPVS-Studioã¢ãã©ã€ã¶ãŒã¯æ¯èŒçæè¿CïŒã³ãŒããåæããããšãåŠã³ãCããã³C ++ãããCïŒã§èšè¿°ããããããžã§ã¯ããã¯ããã«å°ãªããã§ãã¯ããã ãã§ãã
ãã¿ãŒã³ïŒã¯ã©ã¹ã¡ã³ãã¯ããèªèº«ãšæ¯èŒããŸã
æ¯èŒé¢æ°ã¯ãå€ãã®å Žåããã£ãŒã«ãæ§é /ã¯ã©ã¹ã®é 次æ¯èŒã§æ§æãããŸãã ãã®ãããªã³ãŒãã¯ãã¯ã©ã¹ã®ã¡ã³ããŒãèªåèªèº«ãšæ¯èŒãå§ãããšãã«ãšã©ãŒã«ãªããããã§ãã ãã®å Žåããšã©ãŒã®2ã€ã®ãµãã¿ã€ããåºå¥ã§ããŸãã
æåã®ã±ãŒã¹ã§ã¯ããªããžã§ã¯ãã®ååã瀺ãã®ãå¿ããŠã次ã®ããã«æžããŸãã
return m_x == foo.m_x && m_y == m_y && // <= m_z == foo.m_z;
2çªç®ã®å Žåãåããªããžã§ã¯ãåãæžã蟌ã¿ãŸãã
return zzz.m_x == foo.m_x && zzz.m_y == zzz.m_y && // <= zzz.m_z == foo.m_z;
å®éã«ãã®ãã¿ãŒã³ã®ãšã©ãŒã«æ £ããŠã¿ãŸãããã ã¡ãªã¿ã«ã誀ã£ãæ¯èŒã¯ãåãããã¹ããããã¯ã®æåŸã«ããèŠãããããšã«æ³šæããŠãã ããããæåŸã®è¡ã®å¹æãã§ãã
Unreal Engine 4 ïŒC ++ïŒãããžã§ã¯ãã®ã³ãŒãã§ãšã©ãŒãèŠã€ãããŸããïŒ
bool Compare(const FPooledRenderTargetDesc& rhs, bool bExact) const { .... return Extent == rhs.Extent && Depth == rhs.Depth && bIsArray == rhs.bIsArray && ArraySize == rhs.ArraySize && NumMips == rhs.NumMips && NumSamples == rhs.NumSamples && Format == rhs.Format && LhsFlags == RhsFlags && TargetableFlags == rhs.TargetableFlags && bForceSeparateTargetAndShaderResource == rhs.bForceSeparateTargetAndShaderResource && ClearValue == rhs.ClearValue && AutoWritable == AutoWritable; // <= }
èŠåPVS-StudioïŒ V501 ã==ãæŒç®åã®å·Šå³ã«åããµãåŒããããŸãïŒAutoWritable == AutoWritable rendererinterface.h 180
Sambaãããžã§ã¯ãã³ãŒãïŒCïŒïŒ
static int compare_procids(const void *p1, const void *p2) { const struct server_id *i1 = (struct server_id *)p1; const struct server_id *i2 = (struct server_id *)p2; if (i1->pid < i2->pid) return -1; if (i2->pid > i2->pid) return 1; return 0; }
èŠåPVS-StudioïŒ V501 ã>ãæŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒi2-> pid> i2-> pid brlock.c 1901
MongoDBãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool operator==(const MemberCfg& r) const { .... return _id==r._id && votes == r.votes && h == rh && priority == r.priority && arbiterOnly == r.arbiterOnly && slaveDelay == r.slaveDelay && hidden == r.hidden && buildIndexes == buildIndexes; // <= }
èŠåPVS-StudioïŒ V501 '=='æŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒbuildIndexes == buildIndexes rs_config.h 101
Geant4ãœãããŠã§ã¢ãããžã§ã¯ãã³ãŒã ïŒC ++ïŒïŒ
inline G4bool G4FermiIntegerPartition:: operator==(const G4FermiIntegerPartition& right) { return (total == right.total && enableNull == enableNull && // <= partition == right.partition); }
PVS-Studioã®èŠå ïŒ V501 ã==ãæŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸããenableNull == enableNull G4hadronic_deex_fermi_breakup g4fermiintegerpartition.icc 58
LibreOfficeãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
class SvgGradientEntry { .... bool operator==(const SvgGradientEntry& rCompare) const { return (getOffset() == rCompare.getOffset() && getColor() == getColor() // <= && getOpacity() == getOpacity()); // <= } .... }
PVS-StudioèŠåïŒ V501 ã==ãæŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒgetColorïŒïŒ== getColorïŒïŒsvggradientprimitive2d.hxx 61
Chromiumãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool FileIOTest::MatchesResult(const TestStep& a, const TestStep& b) { .... return (a.data_size == a.data_size && // <= std::equal(a.data, a.data + a.data_size, b.data)); }
PVS-StudioèŠåïŒ V501 ã==ãæŒç®åã®å·Šå³ã«åäžã®ãµãåŒããããŸãïŒa.data_size == a.data_size cdm_file_io_test.cc 367
FreeCADãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool FaceTypedBSpline::isEqual(const TopoDS_Face &faceOne, const TopoDS_Face &faceTwo) const { .... if (surfaceOne->IsURational() != surfaceTwo->IsURational()) return false; if (surfaceTwo->IsVRational() != // <= surfaceTwo->IsVRational()) // <= return false; if (surfaceOne->IsUPeriodic() != surfaceTwo->IsUPeriodic()) return false; if (surfaceOne->IsVPeriodic() != surfaceTwo->IsVPeriodic()) return false; if (surfaceOne->IsUClosed() != surfaceTwo->IsUClosed()) return false; if (surfaceOne->IsVClosed() != surfaceTwo->IsVClosed()) return false; if (surfaceOne->UDegree() != surfaceTwo->UDegree()) return false; if (surfaceOne->VDegree() != surfaceTwo->VDegree()) return false; .... }
PVS-Studioã®èŠå ïŒ V501 ãïŒ=ãæŒç®åã®å·ŠåŽãšå³åŽã«ã¯ãåäžã®éšååŒãsurfaceTwo-> IsVRationalïŒïŒãããããŸãã modelrefine.cpp 780
æ·±å»ãªãšã³ãžã³ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
class CTexParams { public: inline BOOL IsEqual( CTexParams tp) { return tp_iFilter == tp.tp_iFilter && tp_iAnisotropy == tp_iAnisotropy && // <= tp_eWrapU == tp.tp_eWrapU && tp_eWrapV == tp.tp_eWrapV; }; .... };
èŠåPVS-StudioïŒ V501 '=='æŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒtp_iAnisotropy == tp_iAnisotropy gfx_wrapper.h 180
Qtãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
inline bool qCompare(QImage const &t1, QImage const &t2, ....) { .... if (t1.width() != t2.width() || t2.height() != t2.height()) { .... }
PVS-StudioèŠåïŒ V501 'ïŒ='æŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒt2.heightïŒïŒïŒ= T2.heightïŒïŒqtest_gui.h 101
FreeBSDãããžã§ã¯ãã³ãŒãïŒCïŒïŒ
static int compare_sh(const void *_a, const void *_b) { const struct ipfw_sopt_handler *a, *b; a = (const struct ipfw_sopt_handler *)_a; b = (const struct ipfw_sopt_handler *)_b; .... if ((uintptr_t)a->handler < (uintptr_t)b->handler) return (-1); else if ((uintptr_t)b->handler > (uintptr_t)b->handler) // <= return (1); return (0); }
PVS-Studioã®èŠå ïŒ V501 ã>ãæŒç®åã®å·Šå³ã«ã¯ãåäžã®å¯æ¬¡åŒãïŒuintptr_tïŒb->ãã³ãã©ãŒãããããŸãã ip_fw_sockopt.c 2893
ã¢ããããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2) { return value1.ClassName == value1.ClassName && // <= value1.Part == value2.Part && value1.State == value2.State; }
PVS-StudioèŠåïŒ V3001 ã==ãæŒç®åã®å·ŠåŽãšå³åŽã«åäžã®ãµãåŒãvalue1.ClassNameãããããŸãã ThemeVisualStyles.cs 2141
ã¢ããããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public int ExactInference (TypeSpec u, TypeSpec v) { .... var ac_u = (ArrayContainer) u; var ac_v = (ArrayContainer) v; .... var ga_u = u.TypeArguments; var ga_v = v.TypeArguments; .... if (u.TypeArguments.Length != u.TypeArguments.Length) // <= return 0; .... }
PVS-StudioèŠåïŒ V3001 ãïŒ=ãæŒç®åã®å·ŠåŽãšå³åŽã«ã¯ãåäžã®ãµãåŒãu.TypeArguments.LengthãããããŸãã generic.cs 3135
MonoDevelopãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
Accessibility DeclaredAccessibility { get; } bool IsStatic { get; } private bool MembersMatch(ISymbol member1, ISymbol member2) { if (member1.Kind != member2.Kind) { return false; } if (member1.DeclaredAccessibility != // <=1 member1.DeclaredAccessibility // <=1 || member1.IsStatic != member1.IsStatic) // <=2 { return false; } if (member1.ExplicitInterfaceImplementations().Any() || member2.ExplicitInterfaceImplementations().Any()) { return false; } return SignatureComparer .HaveSameSignatureAndConstraintsAndReturnTypeAndAccessors( member1, member2, this.IsCaseSensitive); }
PVS-StudioèŠåïŒ V3001 ãïŒ=ãæŒç®åã®å·ŠåŽãšå³åŽã«ã¯ãåäžã®éšååŒãmember1.IsStaticãããããŸãã CSharpBinding AbstractImplementInterfaceService.CodeAction.cs 545
Haikuãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
int __CORTEX_NAMESPACE__ compareTypeAndID(....) { int retValue = 0; .... if (lJack && rJack) { if (lJack->m_jackType < lJack->m_jackType) // <= { return -1; } if (lJack->m_jackType == lJack->m_jackType) // <= { if (lJack->m_index < rJack->m_index) { return -1; } else { return 1; } } else if (lJack->m_jackType > rJack->m_jackType) { retValue = 1; } } return retValue; }
PVS-StudioèŠåïŒ V501 ã<ãæŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒlJack-> m_jackType <lJack-> m_jackType MediaJack.cpp 783
ããäžã«ããŸã£ããåããšã©ãŒããã1ã€ãããŸãã ç§ãç解ããããã«ãã©ã¡ãã®å Žåãã圌ãã¯lJackãrJackã«çœ®ãæããã®ãå¿ããŠããŸãã ã
CryEngine Vãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool CompareRotation(const Quat& q1, const Quat& q2, float epsilon) { return (fabs_tpl(q1.vx - q2.vx) <= epsilon) && (fabs_tpl(q1.vy - q2.vy) <= epsilon) && (fabs_tpl(q2.vz - q2.vz) <= epsilon) // <= && (fabs_tpl(q1.w - q2.w) <= epsilon); }
èŠåPVS-StudioïŒ V501 ã-ãæŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒq2.vz-q2.vz entitynode.cpp 93
ãã¿ãŒã³ïŒæ§é /ã¯ã©ã¹ãµã€ãºã®ä»£ããã«ãã€ã³ã¿ãŒãµã€ãºãèšç®ãã
ãã®ã¿ã€ãã®ãšã©ãŒã¯ãCããã³C ++ããã°ã©ã ã§çºçãã sizeofæŒç®åã®èª€ã£ã䜿çšã«é¢é£ããŠããŸãã ãšã©ãŒã¯ãªããžã§ã¯ãã®ãµã€ãºã§ã¯ãªãããã€ã³ã¿ãŒã®ãµã€ãºãèšç®ããŠããŸãã äŸïŒ
T *a = foo1(); T *b = foo2(); x = memcmp(a, b, sizeof(a));
æ§é äœTã®ãµã€ãºã®ä»£ããã«ããã€ã³ã¿ãŒã®ãµã€ãºãèšç®ãããŸãã ãã€ã³ã¿ãŒã®ãµã€ãºã¯äœ¿çšãããããŒã¿ã¢ãã«ã«ãã£ãŠç°ãªããŸãããéåžžã¯4ãŸãã¯8ãã€ãã§ãã ãã®çµæãæ§é ãå æãããããå€ããŸãã¯å°ãªããã€ãã®ã¡ã¢ãªãæ¯èŒãããŸãã
æ£ããã³ãŒãã¯æ¬¡ã®ãšããã§ãã
x = memcmp(a, b, sizeof(T));
ãŸãã¯
x = memcmp(a, b, sizeof(*a));
ãããç·Žç¿ããŸãããã CryEngine V ïŒC ++ïŒãããžã§ã¯ãã®ã³ãŒãã§ãã®ãããªãšã©ãŒãã©ã®ããã«èŠãããã次ã«ç€ºããŸãã
bool operator==(const SComputePipelineStateDescription& other) const { return 0 == memcmp(this, &other, sizeof(this)); }
PVS-StudioèŠåïŒ V579 memcmpé¢æ°ã¯ããã€ã³ã¿ãŒãšãã®ãµã€ãºãåŒæ°ãšããŠåãåããŸãã ééããããããŸããã 3çªç®ã®åŒæ°ã調ã¹ãŸãã graphicspipelinestateset.h 58
ã¢ã³ãªã¢ã«ãšã³ãžã³4 ïŒC ++ïŒãããžã§ã¯ãã³ãŒãïŒ
bool FRecastQueryFilter::IsEqual( const INavigationQueryFilterInterface* Other) const { // @NOTE: not type safe, should be changed when // another filter type is introduced return FMemory::Memcmp(this, Other, sizeof(this)) == 0; }
PVS-StudioèŠåïŒ V579 Memcmpé¢æ°ã¯ããã€ã³ã¿ãŒãšãã®ãµã€ãºãåŒæ°ãšããŠåãåããŸãã ééããããããŸããã 3çªç®ã®åŒæ°ã調ã¹ãŸãã pimplrecastnavmesh.cpp 172
ãã¿ãŒã³ïŒCmpïŒAãAïŒã®åœ¢åŒã®ç¹°ãè¿ãåŒæ°
å€ãã®å Žåãæ¯èŒé¢æ°ã¯ä»ã®æ¯èŒé¢æ°ãåŒã³åºããŸãã ãã®å Žåãèãããããšã©ãŒã®1ã€ã¯ãåããªããžã§ã¯ããžã®ãªã³ã¯/ãã€ã³ã¿ãŒã2åéä¿¡ãããããšã§ãã äŸïŒ
x = memcmp(A, A, sizeof(T));
ããã§ã¯ããªããžã§ã¯ãAãããèªäœãšæ¯èŒãããŸãããããã¯ãã¡ããæå³ããããŸããã
GDB ïŒCïŒãããã¬ãŒã³ãŒãã§èŠã€ãã£ããšã©ãŒããå§ããŸãã
static int psymbol_compare (const void *addr1, const void *addr2, int length) { struct partial_symbol *sym1 = (struct partial_symbol *) addr1; struct partial_symbol *sym2 = (struct partial_symbol *) addr2; return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value, // <= sizeof (sym1->ginfo.value)) == 0 && sym1->ginfo.language == sym2->ginfo.language && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2) && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2) && sym1->ginfo.name == sym2->ginfo.name); }
èŠåPVS-StudioïŒ V549 'memcmp'é¢æ°ã®æåã®åŒæ°ã¯2çªç®ã®åŒæ°ãšåãã§ãã psymtab.c 1580
CryEngineSDKãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
inline bool operator != (const SEfResTexture &m) const { if (stricmp(m_Name.c_str(), m_Name.c_str()) != 0 || // <= m_TexFlags != m.m_TexFlags || m_bUTile != m.m_bUTile || m_bVTile != m.m_bVTile || m_Filter != m.m_Filter || m_Ext != m.m_Ext || m_Sampler != m.m_Sampler) return true; return false; }
èŠåPVS-StudioïŒ V549 'stricmp'é¢æ°ã®æåã®åŒæ°ã¯2çªç®ã®åŒæ°ãšåãã§ãã ishader.h 2089
PascalABC.NETãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
private List<string> enum_consts = new List<string>(); public override bool IsEqual(SymScope ts) { EnumScope es = ts as EnumScope; if (es == null) return false; if (enum_consts.Count != es.enum_consts.Count) return false; for (int i = 0; i < es.enum_consts.Count; i++) if (string.Compare(enum_consts[i], this.enum_consts[i], true) != 0) return false; return true; }
PVS-StudioèŠåïŒ V3038 'enum_consts [i]'åŒæ°ã 'Compare'ã¡ãœããã«æ°åæž¡ãããŸããã 代ããã«ä»ã®åŒæ°ãæž¡ãå¿ èŠããããŸãã CodeCompletion SymTable.cs 2206
ããã§å°ã説æããŸãã Compareé¢æ°ã®å®éã®åŒæ°ã®ãšã©ãŒïŒ
string.Compare(enum_consts[i], this.enum_consts[i], true)
å®éã«ã¯ã enum_consts [i]ãšthis.enum_consts [i]ã¯ãŸã£ããåãã§ãã ç§ãç解ããŠããããã«ãæ£ããåŒã³åºãã¯æ¬¡ã®ããã«ãªããŸãã
string.Compare(es.enum_consts[i], this.enum_consts[i], true)
ãŸãã¯
string.Compare(enum_consts[i], es.enum_consts[i], true)
ãã¿ãŒã³ïŒãã§ãã¯ã®ç¹°ãè¿ãA == B && A == B
äžè¬çãªããã°ã©ãã³ã°ãšã©ãŒã¯ãåããã§ãã¯ã2åå®è¡ãããå Žåã§ãã äŸïŒ
return A == B && C == D && // <= C == D && // <= E == F;
ãã®ãããªå Žåã2ã€ã®ãªãã·ã§ã³ãå¯èœã§ãã 1ã€ç®ã¯ç¡å®³ã§ãã1ã€ã®æ¯èŒã¯äžèŠã§ãããåçŽã«åé€ã§ããŸãã 2çªç®ã¯ããã«æªãããšã§ãã圌ãã¯ä»ã®å€æ°ããã§ãã¯ãããã£ãã®ã§ãããå°å°ãããŠããŸããã
ãããã«ããããã®ãããªã³ãŒãã«ã¯çŽ°å¿ã®æ³šæãå¿ èŠã§ãã ãã£ãšã²ã©ãæããããŠããã®ãããªãšã©ãŒã¯GCC ïŒCïŒã³ã³ãã€ã©ã³ãŒãã§ãèŠã€ããããããšã瀺ããŸãããã
static bool dw_val_equal_p (dw_val_node *a, dw_val_node *b) { .... case dw_val_class_vms_delta: return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1) && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)); .... }
PVS-Studioã®èŠå ïŒ V501 ã&&ãæŒç®åã®å·Šå³ã«åäžã®å¯æ¬¡åŒãïŒStrcmpïŒa-> v.val_vms_delta.lbl1ãb-> v.val_vms_delta.lbl1ïŒãããããŸãã dwarf2out.c 1428
strcmpé¢æ°ã¯ãåãåŒæ°ã®ã»ããã§2ååŒã³åºãããŸãã
ã¢ã³ãªã¢ã«ãšã³ãžã³4 ïŒC ++ïŒãããžã§ã¯ãã³ãŒãïŒ
FORCEINLINE bool operator==(const FShapedGlyphEntryKey& Other) const { return FontFace == Other.FontFace && GlyphIndex == Other.GlyphIndex // <= && FontSize == Other.FontSize && FontScale == Other.FontScale && GlyphIndex == Other.GlyphIndex; // <= }
PVS-StudioèŠåïŒ V501 ã&&ãæŒç®åã®å·ŠåŽãšå³åŽã«ã¯ãåäžã®å¯æ¬¡åŒãGlyphIndex == Other.GlyphIndexãããããŸãã fontcache.h 139
æ·±å»ãªãšã³ãžã³ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
inline BOOL CValuesForPrimitive::operator==(....) { return ( (....) && (vfp_ptPrimitiveType == vfpToCompare.vfp_ptPrimitiveType) && .... (vfp_ptPrimitiveType == vfpToCompare.vfp_ptPrimitiveType) && .... );
PVS-Studioã®èŠå ïŒ V501 ã&&ãæŒç®åã®å·ŠåŽãšå³åŽã«åäžã®å¯æ¬¡åŒãïŒvfp_ptPrimitiveType == vfpToCompare.vfp_ptPrimitiveTypeïŒãããããŸãã worldeditor.h 580
Oracle VM Virtual Box Project CodeïŒC ++ïŒïŒ
typedef struct SCMDIFFSTATE { .... bool fIgnoreTrailingWhite; bool fIgnoreLeadingWhite; .... } SCMDIFFSTATE; /* Pointer to a diff state. */ typedef SCMDIFFSTATE *PSCMDIFFSTATE; /* Compare two lines */ DECLINLINE(bool) scmDiffCompare(PSCMDIFFSTATE pState, ....) { .... if (pState->fIgnoreTrailingWhite // <= || pState->fIgnoreTrailingWhite) // <= return scmDiffCompareSlow(....); .... }
PVS-StudioèŠåïŒ V501 ã||ãã®å·Šå³ã«åäžã®ãµãåŒãpState-> fIgnoreTrailingWhiteãããããŸãã æŒç®åã scmdiff.cpp 238
ãã¿ãŒã³ïŒmemcmpé¢æ°ã«ãã£ãŠè¿ãããå€ã®èª€çš
memcmpé¢æ°ã¯ã intåã®æ¬¡ã®å€ãè¿ããŸãã
- <0-buf1ã¯buf2ãããå°ããã
- 0-buf1ã¯buf2ãšåäžã
- > 0-buf1ã¯buf2ãã倧ããã
泚æããŠãã ããã ã0ãã倧ããããšã¯ãä»»æã®æ°å€ãæå³ãã1ã§ã¯ãããŸããããããã®æ°å€ã¯ã2ã3ã100ã256ã1024ã5555ã65536ãªã©ã§ãã ããã¯ããã®çµæãcharåãŸãã¯shortåã®å€æ°ã«é 眮ã§ããªãããšãæå³ããŸãã ææãªãããããããããããå¯èœæ§ããããããã°ã©ã å®è¡ããžãã¯ã«éåããŸãã
ãã®ããšãããçµæãå®æ°1ãŸãã¯-1ãšæ¯èŒã§ããªãããšã«ããªããŸãã èšãæããã°ãããééã£ãŠããïŒ
if (memcmp(a, b, sizeof(T)) == 1) if (memcmp(x, y, sizeof(T)) == -1)
æ£ããæ¯èŒïŒ
if (memcmp(a, b, sizeof(T)) > 0) if (memcmp(a, b, sizeof(T)) < 0)
èšèŒãããŠãããšã©ãŒã®é°æ¹¿ãã¯ãã³ãŒããé·æéæ£åžžã«åäœã§ããããšã§ãã æ°ãããã©ãããã©ãŒã ã«åãæ¿ããããã³ã³ãã€ã©ã®ããŒãžã§ã³ãå€æŽããããããšããšã©ãŒãçºçãå§ããå¯èœæ§ããããŸãã
ReactOSãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
HRESULT WINAPI CRecycleBin::CompareIDs(....) { .... return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (unsigned short)memcmp(pidl1->mkid.abID, pidl2->mkid.abID, pidl1->mkid.cb)); }
PVS-StudioèŠåïŒ V642 ãmemcmpãé¢æ°ã®çµæããunsigned shortãåå€æ°å ã«ä¿åããããšã¯äžé©åã§ãã ããã°ã©ã ã®ããžãã¯ãå£ããŠãéèŠãªãããã倱ãããå¯èœæ§ããããŸãã recyclebin.cpp 542
Firebirdãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
SSHORT TextType::compare(ULONG len1, const UCHAR* str1, ULONG len2, const UCHAR* str2) { .... SSHORT cmp = memcmp(str1, str2, MIN(len1, len2)); if (cmp == 0) cmp = (len1 < len2 ? -1 : (len1 > len2 ? 1 : 0)); return cmp; }
PVS-StudioèŠåïŒ V642 ãmemcmpãé¢æ°ã®çµæããshortãåå€æ°å ã«ä¿åããããšã¯äžé©åã§ãã ããã°ã©ã ã®ããžãã¯ãå£ããŠãéèŠãªãããã倱ãããå¯èœæ§ããããŸãã texttype.cpp 338
CoreCLRãããžã§ã¯ãã³ãŒã ïŒC ++ïŒïŒ
bool operator( )(const GUID& _Key1, const GUID& _Key2) const { return memcmp(&_Key1, &_Key2, sizeof(GUID)) == -1; }
PVS-Studioã®èŠå ïŒ V698åŒ 'memcmpïŒ....ïŒ== -1'ã¯æ£ãããããŸããã ãã®é¢æ°ã¯ãå€ã-1ãã ãã§ãªããè² ã®å€ãè¿ãããšãã§ããŸãã 代ããã« 'memcmpïŒ....ïŒ<0'ã®äœ¿çšãæ€èšããŠãã ããã sos util.cpp 142
OpenToonzãããžã§ã¯ãã³ãŒã ïŒC ++ïŒïŒ
bool TFilePath::operator<(const TFilePath &fp) const { .... char differ; differ = _wcsicmp(iName.c_str(), jName.c_str()); if (differ != 0) return differ < 0 ? true : false; .... }
PVS-StudioèŠåïŒ V642 ã_wcsicmpãé¢æ°ã®çµæããcharãåå€æ°å ã«ä¿åããããšã¯äžé©åã§ãã éèŠãªãããã倱ãããããã°ã©ã ã®ããžãã¯ãç Žæããå¯èœæ§ããããŸãã tfilepath.cpp 328
ãã¿ãŒã³ïŒç¡å¹ãªnullåç §ãã§ãã¯
ãã®ãšã©ãŒãã¿ãŒã³ã¯ãCïŒããã°ã©ã ã®å žåçãªãã®ã§ãã æ¯èŒé¢æ°ã§ã¯ã asæŒç®åã䜿çšããŠåãã£ã¹ããå®è¡ãããå ŽåããããŸãã ãšã©ãŒã¯ã nullãžã®äžæ³šæãæ°ãããªã³ã¯ã§ã¯ãªããå ã®ãªã³ã¯ã«å¯ŸããŠãã§ãã¯ããããšããäºå®ã«ãããŸãã åæäŸãèããŠã¿ãŸãããïŒ
ChildT foo = obj as ChildT; if (obj == null) return false; if (foo.zzz()) {}
objå€æ°ã«nullåç §ãå«ãŸããŠããå Žåã ïŒobj == nullïŒãç¶æ³ãä¿è·ãããã©ããã確èªããŸãã ãã ãã asæŒç®åãnullåç §ãè¿ãããšãå€æããå Žåãã±ãŒã¹ã«å¯Ÿããä¿è·ã¯ãããŸããã æ£ããã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
ChildT foo = obj as ChildT; if (foo == null) return false; if (foo.zzz()) {}
ååãšããŠãããã°ã©ããŒã®äžæ³šæã«ãããšã©ãŒãçºçããŸãã Cããã³C ++ããã°ã©ã ã§ãåæ§ã®ãšã©ãŒãçºçããå¯èœæ§ããããŸãããèŠã€ãã£ããšã©ãŒã®ããŒã¿ããŒã¹ã«ã¯ãã®ãããªã±ãŒã¹ã¯èŠã€ãããŸããã§ããã
MonoDevelopãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals (object o) { SolutionItemReference sr = o as SolutionItemReference; if (o == null) return false; return (path == sr.path) && (id == sr.id); }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãoãããsrãã確èªããŸãã MonoDevelop.Core SolutionItemReference.cs 81
CoreFXãããžã§ã¯ãã³ãŒã ïŒCïŒïŒïŒ
public override bool Equals(object comparand) { CredentialHostKey comparedCredentialKey = comparand as CredentialHostKey; if (comparand == null) { // This covers also the compared == null case return false; } bool equals = string.Equals(AuthenticationType, comparedCredentialKey.AuthenticationType, .... .... }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãcomparandãããcomparedCredentialKeyãã確èªããŠãã ããã CredentialCache.cs 4007
ããºãªã³ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals(object obj) { var d = obj as DiagnosticDescription; if (obj == null) return false; if (!_code.Equals(d._code)) return false; .... }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãobjãããdãã確èªããŸãã DiagnosticDescription.cs 201
ããºãªã³ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
protected override bool AreEqual(object other) { var otherResourceString = other as LocalizableResourceString; return other != null && _nameOfLocalizableResource == otherResourceString._nameOfLocalizableResource && _resourceManager == otherResourceString._resourceManager && _resourceSource == otherResourceString._resourceSource && .... }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãotherãããotherResourceStringãã確èªããŠãã ããã LocalizableResourceString.cs 121
MSBuildãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals(object obj) { AssemblyNameExtension name = obj as AssemblyNameExtension; if (obj == null) // <= { return false; } .... }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãobjãããnameãã確èªããŠãã ããã AssemblyRemapping.cs 64
ã¢ããããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals (object o) { UrlMembershipCondition umc = (o as UrlMembershipCondition); if (o == null) // <= return false; .... return (String.Compare (u, 0, umc.Url, ....) == 0); // <= }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãoãããumcãã確èªããŠãã ããã UrlMembershipCondition.cs 111
Media Portal 2ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals(object obj) { EpisodeInfo other = obj as EpisodeInfo; if (obj == null) return false; if (TvdbId > 0 && other.TvdbId > 0) return TvdbId == other.TvdbId; .... }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãobjãããotherãã確èªããŠãã ããã EpisodeInfo.cs 560
NASA World Windãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public int CompareTo(object obj) { RenderableObject robj = obj as RenderableObject; if(obj == null) // <= return 1; return this.m_renderPriority.CompareTo(robj.RenderPriority); }
PVS-StudioèŠåïŒ V3019 ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ° 'obj'ã 'robj'ã確èªããŠãã ããã RenderableObject.cs 199
ãã¿ãŒã³ã¿ã€ãïŒééã£ããµã€ã¯ã«
äžéšã®é¢æ°ã¯ãã¢ã€ãã ã®ã³ã¬ã¯ã·ã§ã³ãæ¯èŒããŸãã åœç¶ãããããæ¯èŒããããã«ãããŸããŸãªãµã€ã¯ã«ãªãã·ã§ã³ã䜿çšãããŸãã æ¯èŒé¢æ°ã§èµ·ããããã«ãã³ãŒããäžæ³šæã«æžããšãã«ãŒããšäœããæ··åãããããªããŸãã ãã®ãããªç¶æ³ãããã€ãèããŠã¿ãŸãããã
ãã©ã³ã¹ããããªãŒã ãã€ãã©ã€ã³ ïŒC ++ïŒãããžã§ã¯ãã³ãŒãïŒ
bool Peptide::operator==(Peptide& p) { .... for (i = 0, j = 0; i < this->stripped.length(), j < p.stripped.length(); i++, j++) { .... }
PVS-StudioèŠåïŒ V521 ãããæŒç®åã䜿çšãããã®ãããªåŒã¯å±éºã§ãã åŒãæ£ããããšã確èªããŠãã ããã tpplibãããã.cpp 191
æ¡ä»¶ã¯ã³ã³ãæŒç®åã䜿çšããããšã«æ³šæããŠãã ããã ã«ã³ãã®å·ŠåŽã®æ¡ä»¶ã¯èæ ®ãããªããããã³ãŒãã¯æããã«æ£ãããããŸããã ã€ãŸããå·ŠåŽã®æ¡ä»¶ãèšç®ãããŸããããã®çµæã¯ãŸã£ãã䜿çšãããŸããã
Qtãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool equals( class1* val1, class2* val2 ) const { ... size_t size = val1->size(); ... while ( --size >= 0 ){ if ( !comp(*itr1,*itr2) ) return false; itr1++; itr2++; } ... }
PVS-Studio èŠåïŒV547åŒ ' -size > = 0'ã¯åžžã«trueã§ãã笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããQtCLucene array.h 154 CLucene
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
class Arrays { .... bool equals( class1* val1, class2* val2 ) const{ static _comparator comp; if ( val1 == val2 ) return true; size_t size = val1->size(); if ( size != val2->size() ) return false; _itr1 itr1 = val1->begin(); _itr2 itr2 = val2->begin(); while ( --size >= 0 ){ if ( !comp(*itr1,*itr2) ) return false; itr1++; itr2++; } return true; } .... }
PVS-Studio èŠåïŒV547åŒ ' -size > = 0'ã¯åžžã«trueã§ãã笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããarrays.h154 Mono
ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals (object obj) { .... for (int i=0; i < list.Count; i++) { bool found = false; for (int j=0; i < ps.list.Count; j++) { // <= if (list [i].Equals (ps.list [j])) { found = true; break; } } if (!found) return false; } return true; }
PVS-StudioèŠåïŒV3015ãforãæŒç®åå ã§ééã£ãå€æ°ãæ¯èŒãããŠããå¯èœæ§ããããŸãããIãcorlib-net_4_xèŠçŽããæ€èš PermissionSet.cs 607
å€æ°ã䜿çšãããã¹ããããã«ãŒãã®ç¶æ ã§ã¯ãã»ãšãã©ã®ã¿ã€ããã¹ãããŠãå®éã«Jã代ããã«ãIïŒ
for (int j=0; j < ps.list.Count; j++)
ãã¿ãŒã³ïŒA = getAïŒïŒãB = GetAïŒïŒ
å€ãã®å Žåãæ¯èŒé¢æ°ã§ã¯ããã®ã¿ã€ãã®ã³ãŒããäœæããå¿ èŠããããŸãã
if (GetA().x == GetB().x && GetA().y == GetB().y)
æ¡ä»¶ã®ãµã€ãºãå°ããããããããŸãã¯æé©åããããã«ãäžéå€æ°ã䜿çšãããŸãã
Type A = GetA(); Type B = GetB(); if (Ax == Bx && Ay == By)
åæã«ã圌ãã¯äžæ³šæã§ééããç¯ããåãå€ã§äžæå€æ°ãåæåããŸãã
Type A = GetA(); Type B = GetA();
å®éã®ã¢ããªã±ãŒã·ã§ã³ã®ã³ãŒãã§ãã®ãããªãšã©ãŒãã©ã®ããã«èŠããããèŠãŠã¿ãŸããããLibreOffice
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool CmpAttr( const SfxPoolItem& rItem1, const SfxPoolItem& rItem2) { .... bool bNumOffsetEqual = false; ::boost::optional<sal_uInt16> oNumOffset1 = static_cast<const SwFmtPageDesc&>(rItem1).GetNumOffset(); ::boost::optional<sal_uInt16> oNumOffset2 = static_cast<const SwFmtPageDesc&>(rItem1).GetNumOffset(); if (!oNumOffset1 && !oNumOffset2) { bNumOffsetEqual = true; } else if (oNumOffset1 && oNumOffset2) { bNumOffsetEqual = oNumOffset1.get() == oNumOffset2.get(); } else { bNumOffsetEqual = false; } .... }
PVS-Studioã®èŠåïŒV656å€æ° 'oNumOffset1'ã 'oNumOffset2'ã¯ãåãé¢æ°ã®åŒã³åºãã«ãã£ãŠåæåãããŸãããããããšã©ãŒãŸãã¯æé©åãããŠããªãã³ãŒãã§ãã68ã69è¡ã確èªããŸããfindattr.cxx69 Qt
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
AtomicComparator::ComparisonResult IntegerComparator::compare(const Item &o1, const AtomicComparator::Operator, const Item &o2) const { const Numeric *const num1 = o1.as<Numeric>(); const Numeric *const num2 = o1.as<Numeric>(); if(num1->isSigned() || num2->isSigned()) .... }
PVS-StudioèŠåïŒV656å€æ° 'num1'ã 'num2'ã¯ãåãé¢æ°ã®åŒã³åºãã«ãã£ãŠåæåãããŸãããããããšã©ãŒãŸãã¯æé©åãããŠããªãã³ãŒãã§ããão1.as <Numeric>ïŒïŒãåŒã®æ€æ»ãæ€èšããŠãã ãããè¡ã確èªããŠãã ããïŒ220ã221ãqatomiccomparators.cpp 221
ãã¿ãŒã³ïŒå€±æããã³ãŒãã®ã³ããŒ
åè¿°ã®ãšã©ãŒã®å€ãã¯ãã³ããŒããŒã¹ãã®å€±æã®çµæãšåŒã¶ããšãã§ããŸãããããã¯ããçš®ã®èª€ã£ããã¿ãŒã³ã«è©²åœãããããã察å¿ããã»ã¯ã·ã§ã³ã§èª¬æããããšãè«ççã§ãããšå€æããŸããããã ããã³ãŒãã®ã³ããŒã倱æããããã«æããã«çºçããããã€ãã®ãšã©ãŒããããŸãããåé¡æ¹æ³ã¯ããããŸãããããã§ããããã®ãšã©ãŒãããã§ã³ã³ãã€ã«ããŸãããCoreCLR
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
int __cdecl Compiler::RefCntCmp(const void* op1, const void* op2) { .... if (weight1) { .... if (varTypeIsGC(dsc1->TypeGet())) { weight1 += BB_UNITY_WEIGHT / 2; } if (dsc1->lvRegister) { weight1 += BB_UNITY_WEIGHT / 2; } } if (weight1) { .... if (varTypeIsGC(dsc2->TypeGet())) { weight1 += BB_UNITY_WEIGHT / 2; // <= } if (dsc2->lvRegister) { weight2 += BB_UNITY_WEIGHT / 2; } } .... }
PVS-StudioèŠåïŒV778åæ§ã®2ã€ã®ã³ãŒããã©ã°ã¡ã³ããèŠã€ãããŸããããããããããã¯ã¿ã€ããã¹ã§ããããweight1ãã®ä»£ããã«ãweight2ãå€æ°ã䜿çšããå¿ èŠããããŸããclrjit lclvars.cpp 2702
ãã®é¢æ°ã¯é·ãã£ãããããã®èšäºã§ã¯å®å šã«ççž®ãããŠããŸããç§ãã¡ã¯ããã®é¢æ°ã®ã³ãŒããèããå Žåãã³ãŒãã®äžéšãã³ããŒãããããšã«é¡èã§ããããäžã€ã®å Žæã«ããã°ã©ãã¯ãå€æ°çœ®ãæããã®ãå¿ããŠweight1ã«WEIGHT2ããMicrosoft
ãããžã§ã¯ãïŒCïŒïŒã«ããWPFãµã³ãã«ã³ãŒãïŒ
public int Compare(GlyphRun a, GlyphRun b) { .... if (aPoint.Y > bPoint.Y) // <= { return -1; } else if (aPoint.Y > bPoint.Y) // <= { result = 1; } else if (aPoint.X < bPoint.X) { result = -1; } else if (aPoint.X > bPoint.X) { result = 1; } .... }
PVS-Studio èŠåïŒV3003ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸãããè«çãšã©ãŒãååšããå¯èœæ§ããããŸããè¡ã確èªããŠãã ããïŒ418ã422ãtxtserializerwriter.cs 418 PascalABC.NET
ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public void CompareInternal(....) { .... else if (left is int64_const) CompareInternal(left as int64_const, right as int64_const); .... else if (left is int64_const) CompareInternal(left as int64_const, right as int64_const); .... }
PVS-Studio èŠåïŒV3003ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸãããè«çãšã©ãŒãååšããå¯èœæ§ããããŸããè¡ã確èªããŠãã ããïŒ597ã631ãParserTools SyntaxTreeComparer.cs 597 SharpDevelop
ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public int Compare(SharpTreeNode x, SharpTreeNode y) { .... if (typeNameComparison == 0) { if (x.Text.ToString().Length < y.Text.ToString().Length) return -1; if (x.Text.ToString().Length < y.Text.ToString().Length) return 1; } .... }
PVS-StudioèŠåïŒV3021åäžã®æ¡ä»¶åŒãæã€2ã€ã®ãifãã¹ããŒãã¡ã³ãããããŸããæåã®ãifãã¹ããŒãã¡ã³ãã«ã¯ã¡ãœããã®æ»ãå€ãå«ãŸããŸãã ããã¯ã2çªç®ã®ãifãã¹ããŒãã¡ã³ããç¡æå³ãªNamespaceTreeNode.csã§ããããšãæå³ããŸã87
Coin3Dãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
int SbProfilingData::operator == (const SbProfilingData & rhs) const { if (this->actionType != rhs.actionType) return FALSE; if (this->actionStartTime != rhs.actionStopTime) return FALSE; if (this->actionStartTime != rhs.actionStopTime) return FALSE; .... }
PVS-StudioèŠåïŒV649åäžã®æ¡ä»¶åŒãæã€2ã€ã®ãifãã¹ããŒãã¡ã³ãããããŸããæåã®ãifãã¹ããŒãã¡ã³ãã«ã¯ãé¢æ°ã®æ»ãå€ãå«ãŸããŸããããã¯ã2çªç®ã®ãifãã¹ããŒãã¡ã³ããç¡æå³ã§ããããšãæå³ããŸããè¡ã確èªããŠãã ããïŒ1205ã1206ãsbprofilingdata.cpp 1206 Spring
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
bool operator < (const aiFloatKey& o) const {return mTime < o.mTime;} bool operator > (const aiFloatKey& o) const {return mTime < o.mTime;}
PVS-StudioèŠåïŒV524ã>ãé¢æ°ã®æ¬äœãã<ãé¢æ°ã®æ¬äœãšå®å šã«åçã§ããããšã¯å¥åŠã§ããassimp 3dshelper.h 470
PVS-Studioã³ãŒãã¢ãã©ã€ã¶ãŒãMySQLïŒC ++ïŒãããžã§ã¯ãã§èŠã€ããæåŸã®ç¹ã«èå³æ·±ãã³ãŒãã¯æ¬¡ã®ãšããã§ãã
static int rr_cmp(uchar *a,uchar *b) { if (a[0] != b[0]) return (int) a[0] - (int) b[0]; if (a[1] != b[1]) return (int) a[1] - (int) b[1]; if (a[2] != b[2]) return (int) a[2] - (int) b[2]; if (a[3] != b[3]) return (int) a[3] - (int) b[3]; if (a[4] != b[4]) return (int) a[4] - (int) b[4]; if (a[5] != b[5]) return (int) a[1] - (int) b[5]; // <= if (a[6] != b[6]) return (int) a[6] - (int) b[6]; return (int) a[7] - (int) b[7]; }
èŠåPVS-StudioïŒV525åæ§ã®ãããã¯ã®ã³ã¬ã¯ã·ã§ã³ãå«ãã³ãŒããè¡680ã682ã684ã689ã691ã693ã695ã®é ç®ã0ããã1ããã2ããã3ããã4ããã1ããã6ãã確èªããŸããsqlrecords.cc 680
ãããããããã°ã©ããŒã¯æåã®æ¯èŒãæžãã次ã«2çªç®ã®æ¯èŒãæžããéå±ã«ãªããŸããããããã£ãŠã圌ã¯ããã¹ããããã¯ãã¯ãªããããŒãã«ã³ããŒããŸããã
if (a[1] != b[1]) return (int) a[1] - (int) b[1];
ãããŠãå¿ èŠãªåæ°ã ãããã°ã©ã ããã¹ãã«æ¿å ¥ããŸããããã®åŸã圌ã¯ã€ã³ããã¯ã¹ãå€æŽããŸããããããå Žæã§ãã¹ãããçµæã¯ééã£ãæ¯èŒã§ããïŒ
if (a[5] != b[5]) return (int) a[1] - (int) b[5];
ã泚æãã®ãšã©ãŒã«ã€ããŠã¯ãããããã¯ãããã°ã©ãã³ã°ããªãã¡ã¯ã¿ãªã³ã°ããã®ä»ãã¹ãŠã®äž»ãªåé¡ãã§è©³ãã説æããŠããŸãïŒãã³ã³ãã€ã©ãæ³å®ããªããã®ç« ãåç §ïŒã
ãã¿ãŒã³ïŒEqualsã¡ãœãããnullåç §ã誀ã£ãŠåŠçããŸã
CïŒã§ã¯ãEqualsã¡ãœãããå®è£ ããŠãnullåç §ãåŒæ°ãšããŠæ¥ãå Žåã«ç¶æ³ãæ£ããåŠçããã®ãæ £ç¿ãšãªã£ãŠããŸããæ®å¿µãªããããã¹ãŠã®ã¡ãœããã®å®è£ ããã®èŠåã«æºæ ããŠããããã§ã¯ãããŸãããGitExtensions
ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals(object obj) { return GetHashCode() == obj.GetHashCode(); // <= }
PVS-Studio èŠåïŒV3115 'null'ã 'EqualsïŒobject objïŒ'ã¡ãœããã«æž¡ããšã 'NullReferenceException'ã«ãªããŸãããGit.hub Organization.cs 14 PascalABC.NET
ãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public override bool Equals(object obj) { var rhs = obj as ServiceReferenceMapFile; return FileName == rhs.FileName; }
PVS-Studioã®èŠåïŒV3115 'null'ã 'Equals'ã¡ãœããã«æž¡ããšã 'NullReferenceException'ã«ãªããŸãããICSharpCode.SharpDevelop ServiceReferenceMapFile.cs 31
ãã®ä»ã®ãã®ä»ã®ãšã©ãŒ
G3Dã³ã³ãã³ãããã¯ïŒC ++ïŒãããžã§ã¯ãã³ãŒãïŒ
bool Matrix4::operator==(const Matrix4& other) const { if (memcmp(this, &other, sizeof(Matrix4) == 0)) { return true; } ... }
PVS-Studio èŠåïŒV575ãmemcmpãé¢æ°ã¯ã0ãèŠçŽ ãåŠçããŸããã3çªç®ãã®åŒæ°ã調ã¹ãŸããgraphics3D matrix4.cpp 269
1ã€ã®éãæ¬åŒ§ãé©åã§ã¯ãããŸããããã®çµæãæ¯èŒããããã€ãæ°ã¯åŒsizeofïŒMatrix4ïŒ== 0ã«ãã£ãŠèšç®ãããŸããã¯ã©ã¹ã®ãµã€ãºã¯0ãã倧ãããããåŒã®çµæã¯0ã§ãããããã£ãŠã0ãã€ããæ¯èŒãããŸãã
æ£ãããªãã·ã§ã³ïŒ
if (memcmp(this, &other, sizeof(Matrix4)) == 0) {
Wolfenstein 3Dãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
inline int operator!=( quat_t a, quat_t b ) { return ( ( ax != bx ) || ( ay != by ) || ( az != bz ) && ( aw != bw ) ); }
PVS-StudioèŠåïŒã&&ãæäœã®V648åªå 床ãã||ãã®åªå 床ãããé«ãæäœãmath_quaternion.h 167
ããå Žæã§ã¯ãæããã«ã||ã®ä»£ããã«èª€ã£ãŠ&&æŒç®åãæžããããã§ãã ã
FlightGearãããžã§ã¯ãã³ãŒãïŒCïŒïŒ
static int tokMatch(struct Token* a, struct Token* b) { int i, l = a->strlen; if(!a || !b) return 0; .... }
PVS-StudioèŠåïŒV595 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããaããã€ã³ã¿ãŒã䜿çšãããŸãããè¡ã確èªããŠãã ããïŒ478ã479ãcodegen.c 478
é¢æ°ã®æåã®åŒæ°ãšããŠNULLãæž¡ããšãé¢æ°ã¯0ãè¿ããšããèãæ¹ã§ãããNULLãã€ã³ã¿ãŒã¯éåç §ãããŸããWinMerge
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
int TimeSizeCompare::CompareFiles(int compMethod, const DIFFITEM &di) { UINT code = DIFFCODE::SAME; ... if (di.left.size != di.right.size) { code &= ~DIFFCODE::SAME; code = DIFFCODE::DIFF; } ... }
PVS-StudioèŠåïŒV519ãã³ãŒããå€æ°ã«ã¯é£ç¶ããŠ2åå€ãå²ãåœãŠãããŸããããããããã¯ééãã§ããè¡ããã§ãã¯ïŒ79ã80ãããŒãžtimesizecompare.cpp 80 ReactOS
ãããžã§ã¯ãã³ãŒãïŒC ++ïŒïŒ
#define IsEqualGUID(rguid1, rguid2) \ (!memcmp(&(rguid1), &(rguid2), sizeof(GUID))) static int ctl2_find_guid(....) { MSFT_GuidEntry *guidentry; ... if (IsEqualGUID(guidentry, guid)) return offset; ... }
PVS-StudioèŠåïŒV512ãmemcmpãé¢æ°ãåŒã³åºããšããããã¡ãŒãguidentryãã®ã¢ã³ããŒãããŒãçºçããŸããoleaut32 typelib2.c 320
ãã€ã³ã¿ãŒã¯ãã¯ãã®æåã®åŒæ°ã§ãããã®çµæããã€ã³ã¿ã®ã¢ãã¬ã¹ãèšç®ãããŸãããããã¯æå³ããããŸããã
æ£ãããªãã·ã§ã³ïŒ
if (IsEqualGUID(*guidentry, guid)) return offset;
IronPythonããã³IronRubyãããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public static bool Equals(float x, float y) { if (x == y) { return !Single.IsNaN(x); } return x == y; }
PVS-StudioèŠåïŒV3024å¥åŠãªæ£ç¢ºãªæ¯èŒïŒx == yãå®çŸ©ããã粟床ã®æ¯èŒã䜿çšããããšãæ€èšããŠãã ããïŒMath.AbsââïŒA-BïŒ<EpsilonãFloatOps.cs 1048 NaNã®
ç¹å¥ãªãã§ãã¯ã®ãã€ã³ãã¯æ確ã§ã¯ãããŸãããæ¡ä»¶ïŒx == yïŒãæºããããå Žåãããã¯ãNaNãããèªäœãå«ãä»ã®å€ãšçãããªããããxãšyã®äž¡æ¹ãNaNãšç°ãªãããšãæå³ããŸããNaNã®ãã§ãã¯ã¯äžèŠã§ãã³ãŒãã次ã®ããã«æžããããšãã§ããŸãã
public static bool Equals(float x, float y) { return x == y; }
ã¢ããããžã§ã¯ãã³ãŒãïŒCïŒïŒïŒ
public bool Equals (CounterSample other) { return rawValue == other.rawValue && baseValue == other.counterFrequency && // <= counterFrequency == other.counterFrequency && // <= systemFrequency == other.systemFrequency && timeStamp == other.timeStamp && timeStamp100nSec == other.timeStamp100nSec && counterTimeStamp == other.counterTimeStamp && counterType == other.counterType; }
PVS-StudioèŠåïŒV3112åæ§ã®æ¯èŒã§ã®ç°åžžãåŒ 'baseValue == other.counterFrequency'å ã«ã¿ã€ããã¹ãååšããå¯èœæ§ããããŸããSystem-net_4_x CounterSample.cs 139
ãããã®ããã°ã©ã ã¯ã©ã®ããã«æ©èœããŸããïŒ
ããããã¹ãŠã®ãšã©ãŒãèŠããšããããã®ããã°ã©ã ããã¹ãŠæ£åžžã«æ©èœããããšã¯é©ãã¹ãããšã§ãã確ãã«ãæ¯èŒé¢æ°ã¯ããã°ã©ã ã§éåžžã«éèŠã§è²¬ä»»ã®ããã¿ã¹ã¯ãå®è¡ããŸãã
ãã®ãããªãšã©ãŒã®ããããã°ã©ã ã®å¥å šæ§ã«ã€ããŠã¯ãããã€ãã®èª¬æããããŸãã
- å€ãã®é¢æ°ã§ã¯ããªããžã§ã¯ãã®äžéšã®ã¿ã誀ã£ãŠæ¯èŒãããŸããåæã«ããã®ããã°ã©ã ã®ã»ãšãã©ã®ã¿ã¹ã¯ã§ã¯ãéšåçãªæ¯èŒã§ååã§ãã
- () , . , , , memcmp char . .
- .
- , ? - !
æ¯èŒé¢æ°ã§æ€åºã§ãããšã©ãŒã®æ°ã瀺ããŸããããããŠããŠããããã¹ãã®å©ããåããŠããã®ãããªæ©èœã®ããã©ãŒãã³ã¹ããã§ãã¯ããå¿ èŠããããŸãã
æ¯èŒæŒç®åãEqualsé¢æ°ãªã©ã®åäœãã¹ããå¿ ãäœæããŠãã ããã
ãã®èšäºãèªãåã«ãå€ãã®äººã¯ãã®ãããªãã¹ãã¯åé·ã§ãããããã§ããšã©ãŒãæããã«ããªãããã«æãããŸããïŒçµå±ã®ãšãããæ¯èŒé¢æ°ã¯äžèŠãšãŠãåçŽã§ã...ããŠãä»ç§ã¯ãããã«é ãããŠãããããããªããã¹ãŠã®ææã瀺ããŸããã
ã³ãŒãã®ã¬ãã¥ãŒãšéç解æããŒã«ã®äœ¿çšãåé·ã§ã¯ãããŸããã
ãããã«
ãã®èšäºã§ã¯ãæèœãªå°é家ã«ãã£ãŠéçºãããå€ãã®æåãªãããžã§ã¯ãã«èšåããŸããããããã®ãããžã§ã¯ãã¯ãããŸããŸãªæ¹æ³è«ã䜿çšããŠå³å¯ã«ãã¹ããããŠããŸããããã§ããããã¯PVS-Studioã¢ãã©ã€ã¶ãŒããšã©ãŒãæ€åºããããšã劚ããŸããã§ãããããã¯ãPVS-Studioãã³ãŒãã®å質ãšä¿¡é Œæ§ãåäžãããããã«äœ¿çšãããä»ã®æ¹æ³è«ã«å€§ããè¿œå ã§ããããšã瀺åããŠããŸãã
åœç€Ÿã®ãŠã§ããµã€ãã«ã¢ã¯ã»ã¹ããŠãPVS-Studioããè©Šããã ããã
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒAndrey Karpovã æ¯èŒé¢æ°å ã®æª