Thread: segmentation fault due to "printf" ?

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    segmentation fault due to "printf" ?

    Hi everyone!

    During a debug of an existing program, the following occurs :
    Code:
      printf( "blabla ", argv[1]) ; // argv[1] is the argument of 'main'
      ret=geo->load(argv[1]);
    now, at time of calling "printf" , the attribute "geo->source" is NULL, but after the call, the value has changed although the printf does not do anything with the object geo, leave alone its members.

    After some more debugging, I have encountered this problem at other printf calls as well.

    Could anyone tell me if I should go looking for a psychiatre or just don't use printf anymore?

    Thanks!!!

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You might give not using printf a try for a couple of weeks and then see the psychiatrist if it doesn't help. Also feel free to consult a psychic.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    If argv[1] is non-null, I would say you are stomping your memory elsewhere.

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    50
    shouldn't it be more like:

    Code:
    printf("blabla  %s", argv[1]);
    Shouldn't cause a seg-fault, but you should at least use printf correctly.

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    There is somethig called "undefined behaviour". It should be "random behaviour". Even better "I am messing with your brain behaviour".
    For your own good, don't overthink why the screen gives you these weird results. There is an error with your program. Most likely something is causing an undefined behaviour and you mess your memory.

    Post more code to spot the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Re: Segmentation fault
    By turkish_van in forum C Programming
    Replies: 8
    Last Post: 01-20-2007, 05:50 PM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM