cs3110 / textbook

The CS 3110 Textbook, "OCaml Programming: Correct + Efficient + Beautiful"
Other
720 stars 132 forks source link

Issue on page /chapters/intro/present.html #52

Closed etherealsunshine closed 2 years ago

etherealsunshine commented 2 years ago

Hello, just wanted to ask that type safety does not prevent buffer overflows as that's a memory error and has nothing to do with the underlying types but how you handle buffers of unknown size right? Thank you and have a nice day!

jnfoster commented 2 years ago

Here "buffer overflows" refers to situations in non-type-safe languages like C, where you can do things like cast an arbitrary variable to void * and then use pointer arithmetic to write into adjacent memory locations. In OCaml, you can't do this, and the type system plays a role, along with automated memory management. Note, that "buffer overrun" doesn't refer to a buffer filling up or referencing an index into a container that doesn't exist. That can happen in OCaml too of course, and implementations of data structures have to deal with it. But you can't go off and corrupt random memory locations.