Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Should x*y exceed SIZE_MAX, malloc(x*y) may be easy to satisfy as the product (after overflow) could be quite small. Of course the memory then allocated is too small. Commented Jan 2, 2018 at 17:18
  • 1
    @chux: That's one of the behavioral differences I noted between malloc(x*y) and calloc(x,y). I've long been irked by the fact that the Standard Library tends to group what should be independent aspects of functionality, like whether an allocation should be scaled and whether it should guarantee the memory is cleared, or--as some other unwelcome pairings, whether a function receiving a line of input should strip out a newline and whether to allow the caller to set a maximum length, or whether a function should output a string to the console versus something else and whether to add a newline. Commented Jan 2, 2018 at 19:33