开发者

C++ code cross compiling to ARM, runtime crash

开发者 https://www.devze.com 2023-02-17 01:05 出处:网络
I\'m fixing a bug about android multimedia framework lower c++ lib.When the code r开发者_如何学运维unning to following position system goto crash.

I'm fixing a bug about android multimedia framework lower c++ lib. When the code r开发者_如何学运维unning to following position system goto crash.

if (((*pChar) >= _T('a')) && ((*pChar) <= _T('z'))) {
    nFrameTime++;
}

nFrameTime is int type;
pChar is wchar_t* type;

But when i modify the code to:

if (((*pChar) >= _T('a')) || ((*pChar) <= _T('z'))) {
    nFrameTime++;
}

Everything is OK. I do not care about using "&&" or "||", I only want to know why that go to crash. Anybody can give me some suggestions?


Most likely pChar isn't pointing at valid data. That's the only thing in there that could really cause a crash (compiler bugs excepted).

The real mystery is why the changed version isn't crashing.

As to the answer to my question, it could be that when you change the code it modifies things just enough that the garbage in pChar happens to point to a valid memory location. Another possibility, as Ben Voigt pointed out in the comments, is that the check is being optimized away in the second version, because any value at all of *pChar will cause it to be true.

0

精彩评论

暂无评论...
验证码 换一张
取 消