home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,906 of 243,242   
   Andrey Tarasevich to Waldek Hebisch   
   Re: NULL dereference in embedded [was: O   
   07 Jan 26 20:48:03   
   
   From: noone@noone.net   
      
   On Tue 1/6/2026 5:08 AM, Waldek Hebisch wrote:   
   >   
   > I get the following assembly:   
   >   
   > 00000000 :   
   >     0:   b108            cbz     r0, 6    
   >     2:   2000            movs    r0, #0   
   >     4:   4770            bx      lr   
   >     6:   6803            ldr     r3, [r0, #0]   
   >     8:   deff            udf     #255    @ 0xff   
   >     a:   bf00            nop   
   >   
   > So compiler generates actiual access, but then, instead of returning   
   > the value it executes undefined opcode.  Without test for null   
   > pointer I get simple access to memory.   
   >   
      
   When it comes to invalid (or missing, in C++) `return` statements, GCC   
   tends to adhere to a "punitive" approach in optimized code - it injects   
   instructions to deliberately cause a crash/segfault in such cases.   
      
   Clang on the other hand tends to stick to the uniform approach based on   
   the "UB cannot happen" methodology, i.e. your code sample would be   
   translated under "p is never null" assumption, and the function will   
   fold into a simple unconditional `return 0`.   
      
   --   
   Best regards,   
   Andrey   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca