Re: Implementation of Virtual Memory on Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 16 May 2006 03:33, Mulyadi Santosa wrote:
> poarray=(char*)malloc(SIGPAGE);
> memset(poarray, '\0', SIGPAGE);
> if(poarray==NULL)
> {
> 	printf("\nError in allocating\n");
> 	exit(1);
> }

I just subscribed to the list, so I don't have the full context of this 
discussion. Anyway, I'd just like to point out a fairly common mistake 
we sometimes make by using a pointer before/without checking for null.

It's good that you checked the pointer for null in the code above, but 
pay attention to the fact that, if it were null, your code would have 
dereferenced it already and would have crashed. The memset() you do 
_before_ checking for null will write to the location your pointer 
points to, and if it is really null your if will never be executed.

Just my two cents. :)
fabio.olive
-- 
ex sed lex awk yacc, e pluribus unix, amem

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux