Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:58:43+00:00 2026-05-30T18:58:43+00:00

I’m following ‘Learn C the Hard Way’, specifically the chapter on Valgrind . This

  • 0

I’m following ‘Learn C the Hard Way’, specifically the chapter on Valgrind. This chapter gives you a deliberately wrong program to show how Valgrind works.

When I run the exercise under Valgrind I do not get line numbers in my stack trace, just ‘(below main)’ for the errors.

I am definitely compiling with the -g flag.

My Valgrind output is as follows:

djb@twin:~/projects/Learning/C$ valgrind ./ex4
==5190== Memcheck, a memory error detector
==5190== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==5190== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==5190== Command: ./ex4
==5190== 
==5190== Use of uninitialised value of size 4
==5190==    at 0x4078B2B: _itoa_word (_itoa.c:195)
==5190==    by 0x407CE55: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
==5190== Conditional jump or move depends on uninitialised value(s)
==5190==    at 0x4078B33: _itoa_word (_itoa.c:195)
==5190==    by 0x407CE55: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
==5190== Conditional jump or move depends on uninitialised value(s)
==5190==    at 0x407CC10: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
==5190== Conditional jump or move depends on uninitialised value(s)
==5190==    at 0x407C742: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
I am 0 years old.
I am 68882420 inches tall.
==5190== 
==5190== HEAP SUMMARY:
==5190==     in use at exit: 0 bytes in 0 blocks
==5190==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==5190== 
==5190== All heap blocks were freed -- no leaks are possible
==5190== 
==5190== For counts of detected and suppressed errors, rerun with: -v
==5190== Use --track-origins=yes to see where uninitialised values come from
==5190== ERROR SUMMARY: 22 errors from 4 contexts (suppressed: 11 from 6)

I’m using Ubuntu 11.10 in a VirtualBox VM.

Thank you for any help.

Update

It seems that if I call a function from main() and that function contains a mistake (eg an uninitialized variable), then I do get a trace to the place that function was called in main(). However errors within main() remain unspecified. See this paste for an example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:58:44+00:00Added an answer on May 30, 2026 at 6:58 pm

    The output you provided in your question contains the following line:

    ==5190== Use --track-origins=yes to see where uninitialised values come from
    

    Per this message you should run ./ex4 like this:

    valgrind --track-origins=yes ./ex4
    

    To avoid some problems with Valgrind unable to find debug information, you can use static linking:

    gcc -static -g  -o ex4  ex4.c 
    

    Valgrind’s output will then contain messages like Uninitialised value was created by a stack allocation:

    ==17673== Memcheck, a memory error detector
    ==17673== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
    ==17673== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
    ==17673== Command: ./ex4
    ...
    ==17673== Use of uninitialised value of size 4
    ==17673==    at 0x805CA7B: _itoa_word (in /home/user/ex4)
    ==17673==    by 0x8049D5F: printf (in /home/user/ex4)
    ==17673==    by 0x8048ECD: main (ex4.c:8)
    ==17673==  Uninitialised value was created by a stack allocation
    ==17673==    at 0x8048EFA: bad_function (ex4.c:17)
    ...
    ==17673== Use of uninitialised value of size 4
    ==17673==    at 0x805CA7B: _itoa_word (in /home/user/ex4)
    ==17673==    by 0x8049D5F: printf (in /home/user/ex4)
    ==17673==    by 0x80490BE: (below main) (in /home/user/ex4)
    ==17673==  Uninitialised value was created by a stack allocation
    ==17673==    at 0x8048EBE: main (ex4.c:4)
    ...
    I am -1094375076 years old.
    ...
    I am -1094369310 inches tall.
    ...
    ==17673== 
    ==17673== HEAP SUMMARY:
    ==17673==     in use at exit: 0 bytes in 0 blocks
    ==17673==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
    ==17673== 
    ==17673== All heap blocks were freed -- no leaks are possible
    ==17673== 
    ==17673== For counts of detected and suppressed errors, rerun with: -v
    ==17673== ERROR SUMMARY: 83 errors from 21 contexts (suppressed: 0 from 0)
    

    File ex4.c:

     1  #include <stdio.h>
     2
     3  int main()
     4  {
     5          int age = 10;
     6          int height;
     7
     8          bad_function();
     9
    10          printf("I am %d years old.\n");
    11          printf("I am %d inches tall.\n", height);
    12
    13          return 0;
    14  }
    15
    16  int bad_function() 
    17  {
    18          int x;
    19          printf("%d\n", x);
    20  }
    

    Valgrind’s output isn’t ideal. It identifies the stack frame (function) containing the uninitialized variable, but it does not print the name of the variable.

    Running Linux under VirtualBox has no effect on Valgrind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.