zhililab / Znotes

个人随记,个人规划
0 stars 0 forks source link

C++ 基础 #25

Open zhililab opened 4 years ago

zhililab commented 4 years ago

工欲善其事,必先利其器

知识 + 汗水 + 灵感 + 机遇

zhililab commented 3 years ago

智能指针

void my_func()
{
    int* valuePtr = new int(15);
    int x = 45;
    // ...
    if (x == 45)
        return;   // here we have a memory leak, valuePtr is not deleted
    // ...
    delete valuePtr;
}

int main()
{
}

using the unique_prt<> template:

#include <memory>

void my_func()
{
    std::unique_ptr<int> valuePtr(new int(15));
    int x = 45;
    // ...
    if (x == 45)
        return;   // no memory leak anymore!
    // ...
}

int main()
{
}

对比

unique_ptr vs shared_ptr vs weak_ptr vs auto_ptr

image

-- 参考资料: https://en.cppreference.com/book/intro/smart_pointers https://juejin.cn/post/6844903993055920141

zhililab commented 3 years ago

Casting

image

https://docs.microsoft.com/en-us/cpp/cpp/casting-operators?view=vs-2019 https://juejin.cn/post/6844903808670105608

zhililab commented 3 years ago

Android 源码编译

官方指导文档

link image

编译器相关

编译器

 Android编译主要包括对C,C++,的编译,这里主要是GCC,G++,编译器,针对ARM平台的编译器,主要是arm-eabi-编译器, 还有针对JAVA的编译器,就是JDK via link

环境配置

ubuntu-18.04.4 Android系统源码R(Android 11)下载及编译

代码下载环境配置,以及各种踩坑

安全扫描

Coverity Analysis for C/C++

Coverity Static Application Security Testing (SAST) COVERITY 2018版C语言编译器支持清单

zhililab commented 3 years ago

https://stackoverflow.com/questions/64042641/no-files-emitted-warning

image

zhililab commented 3 years ago

https://community.synopsys.com/s/article/cli-integration-cheatsheet

image

zhililab commented 3 years ago

https://community.synopsys.com/s/article/Coverity-cov-build-finishes-with-No-files-emitted-for-C-Cplusplus-code

image

or the second reason, because the executable names are different, there is no match, therefore Coverity only logs the name of the executable in "build-log.txt" and creates no ASTs to analyze. To fix this, look thorough the build log for lines containing the text "EXECUTING:" where no subsequent "COMPILING:" line is visible with the same information about the compiler executable. An example of a common mistake is to configure Coverity for a default "GNU" compiler using "cov-configure --gcc", where we monitor for executables named "gcc" and "g++", but really be using a GCC cross-compiler that has a different name (for example "arm-none-eabi-g++ " ), or naming your GNU compiler something different (such as 'cc' or 'c++').