Announcement

Collapse
No announcement yet.

C help needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    And you always need a Borland compiler around dude!

    Comment


    • #17
      Originally posted by VetLegion
      You crazy Indian, you are writing to memory that isn't yours!

      This offset:

      (n-1)*l + m

      Is going to be larger than the

      (n-1)*(n-1)

      you are allocating.

      You can solve this much more elegantly without pointers BTW.
      Why does that break the free()?

      Comment


      • #18
        Originally posted by VetLegion
        Well the natural way would be array, saving you some calculation and being easier to read and slightly harder to mess up. I have to run, maybe I'll come back to this later and we can discuss your code
        Arrays are pointers

        Comment


        • #19
          Originally posted by Kuciwalker


          Why does that break the free()?
          That's something even I'd like to know.

          Comment


          • #20
            Ehrm, writing outside the allocated memory usually means that you are writing in memory management data, so no wonder why you chrash
            With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

            Steven Weinberg

            Comment


            • #21
              It should just segfault though...

              Comment


              • #22
                Originally posted by Kuciwalker


                Arrays are pointers
                Silly theoreticians
                Solver, WePlayCiv Co-Administrator
                Contact: solver-at-weplayciv-dot-com
                I can kill you whenever I please... but not today. - The Cigarette Smoking Man

                Comment


                • #23
                  Originally posted by Kuciwalker
                  It should just segfault though...
                  Well, that too gives a core dump. Wonder actually what system he is using since I usually get the reason why I get a core dump - that is something more informing than "Aborted (core dumped)".
                  With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                  Steven Weinberg

                  Comment


                  • #24
                    Originally posted by Kuciwalker
                    It should just segfault though...
                    No. The way it works is that the C lib for efficiency will allocate a big chunk of memory (one or more pages) at a time, and then give you little peices each time you call malloc.

                    The malloc implementation is free to use some of its allocated memory for control structures, for example a linked list of allocated memory. For example the elements of this list could be interspersed with the actual malloced memory.

                    So if you allocate 16 bytes, but write 20 to the pointer you get, you will, say, overwrite the linked list head of the following element in malloc's linked list. So when you call free() it will find an invalid data structure.

                    For debugging, and depending on the compiler, you can instruct the compiler to link against an alternative malloc implementation which is implemented to discover any corruption sooner.
                    http://www.hardware-wiki.com - A wiki about computers, with focus on Linux support.

                    Comment


                    • #25
                      Originally posted by Solver


                      Silly theoreticians
                      wtf?

                      Comment


                      • #26
                        Only a theoretician could say that pointers are arrays in such a context. And yes, I know that it's true
                        Solver, WePlayCiv Co-Administrator
                        Contact: solver-at-weplayciv-dot-com
                        I can kill you whenever I please... but not today. - The Cigarette Smoking Man

                        Comment

                        Working...
                        X