Skip to content

incorrect/misleading error message for null pointer pointer arithmetic outside a valid region #109

Description

@whyvn

when attempting to perform pointer arithmetic on a null pointer dcc complains that its dereferencing a null pointer. valgrind and clang with ub and address sanitisers dont complain about this issue

mre:

int main(void) {
  (void)((int *)0+0);
  return 0;
}
Runtime error: accessing a value via a NULL pointer
dcc explanation: You are using a pointer which is NULL
  A common error is accessing *p when p == NULL.                                
                    
Execution stopped in main() in test.c at line 2:

int main(void) {
--> (void)((int *)0+0);
    return 0;   
}            
 
Don't understand?  Get AI-generated help by running: dcc-help, or interactive he
lp with dcc-sidekick         

even weirder, when the pointer is initialised to anything other than 0, this error doesnt occur even though its undefined behaviour to initialise to an aitrary non zero integer and its also still ub to perform pointer arithmetic on these values.
and even moree weirder, some types such as char * and void * dont trigger this error but it seems like any other type does

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions