Giter VIP home page Giter VIP logo

Comments (4)

fasterit avatar fasterit commented on August 20, 2024

For sure. The code can use a good makeover for more defensive programming and avoiding of overflows. Patches welcome.

from htop.

BenBE avatar BenBE commented on August 20, 2024

Having the source compile with the following compiler settings is a good start:

-dP
-pedantic
-Wall
-Wextra
-Werror
-Wunused-parameter
-Wduplicated-cond
-Wduplicated-branches
-Wunreachable-code
-Wshadow # Patches incoming; not much to do though
-Winit-self
-Wrestrict
-Wnull-dereference
-Wpointer-arith
-Wcast-align
-Wfloat-equal
-Wlogical-op
-Wwrite-strings
-Wformat=2
-Wno-error=expansion-to-defined
-Wstrict-overflow=5
-Wconversion # Patches incoming, cf. #78
-Wundef
-Wswitch-default
-Wswitch-enum
-fno-strict-aliasing

from htop.

BenBE avatar BenBE commented on August 20, 2024

The suggested set of compiler flags build correctly with both #101 and #102 applied.

from htop.

BenBE avatar BenBE commented on August 20, 2024

As I see some patches coming in using the GCC attributes, I had a look at some of my projects and saw, that one feature that could be interesting in the long run, might be buffer access tracking:

// Allow to use the GCC10 access attribute even with older compilers (by ignoring it if unsupported)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 10)
#define HTOP_CHK_R1(x) __attribute__((access(read_only,x)))
#define HTOP_CHK_RW1(x) __attribute__((access(read_write,x)))
#define HTOP_CHK_W1(x) __attribute__((access(write_only,x)))

#define HTOP_CHK_R(x,y) __attribute__((access(read_only,x,y)))
#define HTOP_CHK_RW(x,y) __attribute__((access(read_write,x,y)))
#define HTOP_CHK_W(x,y) __attribute__((access(write_only,x,y)))
#else
#define HTOP_CHK_R1(x)
#define HTOP_CHK_RW1(x)
#define HTOP_CHK_W1(x)

#define HTOP_CHK_R(x,y)
#define HTOP_CHK_RW(x,y)
#define HTOP_CHK_W(x,y)
#endif

Basically what these attributes do (applied to a function declaration) is mark the argument at location x to contain a pointer to y items of the type that the argument at index x points to.

Example:

__attribute__((access(read_only,1,2)))
__attribute__((nonnull(1)))
void foo(const uint8_t* buf, size_t bufsize) {
    // …
    uint8_t bar = buf[bufsize]; // <- Throws warning
    // …
}

Using the nonnull attribute here also allows to skip the NULL check, as the compiler ensures this can't be NULL when this function is called.

from htop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.