User Activity

  • Posted a comment on discussion Development on cppcheck

    #include <stdio.h> #include <stdint.h> enum big_enum { AAA = 0, BBB = UINT64_MAX }; int main() { enum big_enum my_enum = BBB; printf("size: %zu. val=0x%X\n", sizeof(enum big_enum), my_enum >> 32); return 0; } Checking test.c ... test.c:9:68: error: Shifting 32-bit value by 32 bits is undefined behaviour [shiftTooManyBits] printf("size: %zu. val=0x%X\n", sizeof(enum big_enum), my_enum >> 32); ^

  • Posted a comment on discussion Development on cppcheck

    #include <stdio.h> int return_false(); int main() { int array[10]; int idx = 0; if(return_false()) { array[idx++] = 1; } for(int i = 0; i < idx; i++) { printf("%i\n", array[i]); } return 0; } Cppcheck outputs: Checking test.c ... test.c:15:24: error: Uninitialized variable: array [uninitvar] printf("%i\n", array[i]); ^ test.c:9:20: note: Assuming condition is false if(return_false()) ^ test.c:15:24: note: Uninitialized variable: array printf("%i\n", array[i]); ^

  • Posted a comment on discussion Development on cppcheck

    #include <stdio.h> #define CAT_HELP(A,B) A##B #define CAT(A,B) CAT_HELP(A,B) #define NAME(ID) CAT(bc,ID) #define FUNC_NAME(ID) CAT(NAME(ID),_handler) // void CAT(NAME(module_1),_handler)() // Changing to this makes the error disappear void FUNC_NAME(module_1)() { printf("Hello\n"); } int main() { bcmodule_1_handler(); } Cppcheck outputs: Checking ..\test.c ... ..\test.c:3:0: error: failed to expand 'FUNC_NAME', Invalid ## usage when expanding 'CAT_HELP': Unexpected token ')' [preprocessorErrorDirective]...

  • Posted a comment on discussion General Discussion on cppcheck

    For gcc yes. But there are other compilers in the world for example chess compiler from Synopsys takes lines like _symbol myvar 123 without semicolon in the end

  • Modified a comment on discussion Development on cppcheck

    Please remove this thread. Sorry

  • Modified a comment on discussion Development on cppcheck

    We have a system on which the minimum storage unit is 16 bits, meaning sizeof(uint16_t) == 1 and Size passed to mem functions is also in 16 bits. Therefore we have: #define SIZEOF(x) sizeof(x)/sizeof(uint16_t) A typical example: #define SIZEOF(x) sizeof(x)/sizeof(uint16_t) int main() { uint16_t aaa[10]; memset(aaa, 0, SIZEOF(aaa)); } Cppcheck reports: test.c:11:20: warning: Division by result of sizeof(). memset() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]...

  • Posted a comment on discussion Development on cppcheck

    We have a system on which the minimum storage unit is 16 bits, meaning sizeof(uint16_t) == 1 and Size passed to mem functions is also in 16 bits. Therefore we have: #define SIZEOF(x) sizeof(x)/sizeof(uint16_t) A typical example: #define SIZEOF(x) sizeof(x)/sizeof(uint16_t) int main() { uint16_t aaa[10]; memset(aaa, 0, SIZEOF(aaa)); } Cppcheck reports: test.c:11:20: warning: Division by result of sizeof(). memset() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]...

  • Posted a comment on discussion General Discussion on cppcheck

    Cppcheck reports syntaxError on the following code: #define DEF_VAR(NAME,ADDR) _symbol NAME ADDR DEF_VAR(nice_name, 0x00) Output: Checking test.h ... test.h:5:1: error: syntax error [syntaxError] DEF_VAR(nice_name, 0x00) ^ I stepped into the source code and it turned out to be that the syntax error was due to missing ';' at the end, therefore an exception was raised during preprocessing(simplifyTokens). It doesn't pass the symbol name (DEF_VAR) to the error message, so errors on this symbol will...

View All

Personal Data

Username:
viwx
Joined:
2018-07-05 08:56:04

Projects

  • No projects to display.

Personal Tools

MongoDB Logo MongoDB