LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-04-2012, 08:47 AM   #16
errigour
Member
 
Registered: May 2009
Posts: 278

Rep: Reputation: 5

struct areas *top = NULL;
top = malloc(sizeof (top));

someone told me to make sure it's
top = malloc(sizeof(struct areas));

sorry I posted here.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-04-2012, 08:58 AM   #17
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,142

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
Quote:
Originally Posted by errigour View Post
I'm still curious about what you meant in posting the above link.

There is one link to source code on that page and that source code uses the name "top" in a conceptually similar way to what is probably in the program you are debugging. But neither the bug you just described
Code:
top = malloc(sizeof (top));
nor the strange Valgrind symptom you described earlier
Code:
if ( top== NULL)
correspond to anything in that source code.

Now that you posted the source code of the bug, it was easy to identify your other thread, containing a better discussion of that bug:
http://www.linuxquestions.org/questi...ed-4175430177/

Looking at just your post directly above this (before finding your other thread) I was tempted to make the same suggestion as appears at the bottom of the reply you already got here:
http://www.linuxquestions.org/questi...7/#post4795948

That can be a cleaner approach in complicated projects, because it avoids putting information, (the struct name) that might be changed in subsequent program revisions, in a place where the compiler could not see the bug if you made such a change in one place but not the other.

You should understand sizeof(*top) is not computed at run time and is not the size of the actual object top points to (which might be NULL). It is computed at compile time and is the size of the kind of object that top should point to.

sizeof(top) is the size of the pointer, not the size of what it does and/or should point to.

Last edited by johnsfine; 10-04-2012 at 09:20 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting "Short read in buffer_copy" error with "dpkg" stalefries Linux - Software 6 03-24-2010 04:19 PM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 05:23 AM
error: Error for wireless request "Set Mode" (8B06) : invalid argument "roaming" penguin chick Linux - Wireless Networking 5 08-22-2008 02:16 PM
"capset: Operation not permitted" error when I run valgrind. rsravi74 Linux - Newbie 1 09-02-2007 06:30 PM
valgrind crashes at start up with "Killed" error message lasindi Slackware 0 04-22-2006 09:54 PM


All times are GMT -5. The time now is 09:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration