19

盘点 C++ 开源项目中的十大 Bug

 3 years ago
source link: https://www.infoq.cn/article/1xBVGHDW3EbNDBD1eM81
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

又一年即将结束,是时候盘点一下开源项目中的 Bug 了。2020 年的盘点可能还需要点时间,本文我们先来看看 2019 年开源 C/C++ 项目中遇到的一些最有趣的槽点。

No. 10. 我们正运行在什么操作系统上?

V1040 可能拼写错误预定义宏名称。’ MINGW32_‘有点儿像’ MINGW32__’。winapi.h 4112

复制代码

#if !defined(__UNICODE_STRING_DEFINED) && defined(__MINGW32_)

#define __UNICODE_STRING_DEFINED

#endif

MINGW32_ 宏的名称拼写有误(MINGW32 实际上被声明为MINGW32__)。在项目的其它地方,拼写是正确的:

IfYni2i.png!mobile

顺便说一句,这个 bug 并不是在文章"CMake: the Case when the Project’s Quality is Unforgivable"中首次被描述,而是在一个开源项目的 V1040 诊断中就真正被第一次发现的 bug(2019 年 8 月 19 日)。

https://www.viva64.com/en/b/0658/?ref=hackernoon.com

No. 9. 哪个先?

V502 可能’?:‘运算符的工作方式与预期不符。’?:‘运算符的优先级比’=='运算符低。mir_parser.cpp 884

复制代码

enum Opcode : uint8 {

kOpUndef,

....

OP_intrinsiccall,

OP_intrinsiccallassigned,

....

kOpLast,

};

bool MIRParser::ParseStmtIntrinsiccall (StmtNodePtr &stmt, bool isAssigned) {

Opcode o = !isAssigned ? (....)

: (....);

auto *intrnCallNode = mod.CurFuncCodeMemPool()->New<IntrinsiccallNode>(....);

lexer.NextToken();

if (o == !isAssigned ? OP_intrinsiccall : OP_intrinsiccallassigned) {

intrnCallNode->SetIntrinsic(GetIntrinsicID(lexer.GetTokenKind()));

} else {

intrnCallNode->SetIntrinsic( static_cast <MIRIntrinsicID>(....));

}

....

}

我们感兴趣的下面的部分:

复制代码

if ( o == !isAssigned ? OP_intrinsiccall : OP_intrinsiccallassigned) {

....

}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK