Thread: malloc char** seg faults

  1. #31
    Registered User
    Join Date
    Nov 2018
    Quote Originally Posted by Salem View Post
    So where exactly did you post any evidence that you saw an "after malloc" and then a segfault?
    really you are still arguing with me about this? really?

    it is all within the first three post, post 1, everything, post 2 the accusation that actually came from you,
    Quote Originally Posted by Salem View Post
    > printf("after malloc %s %s\n", path,*names);
    You only just allocated names, and now you're trying to dereference it.
    post 3 me clarifying it to you

    Quote Originally Posted by poorboy View Post
    all of them printf's came after it already was blowing up (seg faulting). .....
    AFTER it was seg faulting, key word after the fact .that you and others keep insisting was and is the cause of it seg faulting, when if you go back and look at my code I posed it its entirety, it is hiding up in listdir the same type of printf. that was there BEFORE the fact, that I did not catch. you and others got caught up in what you said was the cause of it, even after I clearly pointed out that there is no way that that printf you say is causing it could be the cause of it and the reason why. yet you still are insisting that it is. even after I pointed that fact out.

    who is not really paying attention to details here?

    call in main
    >         printf("after malloc %s %s\n", path,*names);
    You only just allocated names, and now you're trying to dereference it.
    placed in there after it was seg faulting then pointing that fact out to you when you pointed to it being the reason.

    call in listdir
    char ** listdir(const char *name, char *names, int indent)
    {printf("listdir %s, %s, %d\n", name,*names,indent);
    that was there prior to me placing the printf's in main. that was coming up NULL after malloc took place. because it was still empty.
    Last edited by poorboy; 11-29-2018 at 07:58 AM.

  2. #32
    Registered User Kernelpanic's Avatar
    Join Date
    Sep 2018
    Quote Originally Posted by laserlight View Post
    Look at the code I posted in post #14. I compiled and ran that code without a segmentation fault.
    I can not compile it - code from "poorboy" + "laserlight"; see the screenshot.

    The discussion went a bit out of joint. . . keep cool


    malloc char** seg faults-segmentfault1_2018-11-29_172009-jpg

    GCC Version
    malloc char** seg faults-gcc-version-jpg

  3. #33
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    OP knows everything, nothing to see here.
    Move along.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 04-02-2014, 05:29 PM
  2. Replies: 9
    Last Post: 11-18-2008, 02:59 AM
  3. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  4. Replies: 5
    Last Post: 12-22-2005, 06:50 PM
  5. How to malloc (char **)
    By Stack Overflow in forum C Programming
    Replies: 2
    Last Post: 05-06-2004, 07:24 PM

Tags for this Thread