Page 7 of 31. Showing 310 results (0.811 seconds)
INT17-C. Define integer constants in an implementation-independent manner
bits in mask to 1 */ const unsigned long mask = 0xFFFFFFFF; unsigned long flipbits(unsigned long x) { return x ^ mask; } However, on implementations where … and objects of type unsigned char shall be represented using a pure binary notation. /* (Correct) Set all bits in mask to 1 */ const unsigned long mask = -1MEM54-CPP. Provide placement new with properly aligned pointers to sufficient storage capacity
in some situations, assuming they do in all cases is unsafe. #include <cstddef> #include <new> struct S { S (); ~S (); }; void f() { const unsigned N … ) || defined(__GNUG__) const size_t overhead = sizeof(size_t); #else static_assert(false, "you need to determine the size of your implementation's array overheadPOS37-C. Ensure that privilege relinquishment is successful
into account that the lists may differ wrt the egid */ int eql_sups(const int cursups_size, const gid_t* const cursups_list, const int targetsups_size, const gid_t* const targetsups_list) { int i; int j; const int n = targetsups_size; const int diff = cursups_size - targetsups_size; const gid_t egidGCC
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152101 -Ww STR05-C. Use pointers to const when referring to string literals … a const qualification https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152191 Can detect violationsEXP42-C. Do not compare padding data
<string.h> struct s { char c; int i; char buffer[13]; }; void compare(const struct s *left, const struct s *right) { if ((left && right) && (0 … comparing any padding bytes: #include <string.h> struct s { char c; int i; char buffer[13]; }; void compare(const struct s *left, const struct s *rightCON53-CPP. Avoid deadlock by locking in a predefined order
; public: std::mutex balanceMutex; BankAccount() = delete; explicit BankAccount(int initialAmount) : balance(initialAmount) {} int get_balance() const … is initialized. #include <atomic> #include <mutex> #include <thread> class BankAccount { static std::atomic<unsigned int> globalId; const unsigned int id; intSTR34-C. Cast characters to unsigned char before converting to larger integer sizes
pointers or array subscripts: #include <limits.h> #include <stddef.h> static const char table[UCHAR_MAX + 1] = { 'a' /* ... */ }; ptrdiff_t first_not_in_table(const char *c_str) { for (const char *s = c_str; *s; ++s) { if (table[(unsigned int)*s] != *s) { return s - c_str; } } return -1; } CompliantECLAIR
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152105 CC2.DCL00 DCL00-C. Const-qualify immutable objects … https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152357 CC2.DCL13 DCL13-C. Declare function parameters that are pointers to values not changed by the function as constARR30-C. Do not form or use out-of-bounds pointers or array subscripts
member */ }; const char *find(const struct S *s, int c) { const char *first = s->buf; const char *last = s->buf + s->len; while (first++ != last … a value past the pointer's current value is known to exist: #include <stdlib.h> struct S { size_t len; char buf[]; /* Flexible array member */ }; constEXP37-C. Call functions with the correct number and type of arguments
with the referenced type, the behavior is undefined. See undefined behavior 25. #include <stdio.h> #include <string.h> char *(*fp)(); int main(void) { const … : #include <stdio.h> #include <string.h> char *(*fp)(const char *, int); int main(void) { const char *c; fp = strchr; c = fp("Hello",'e'); printf("%s\n", c