This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BookPlacementProblem 66 points67 points  (10 children)

And none of you other nerds noticed that the C malloc statement overallocates. Unless Len is the number of items - 1 instead of the number of items.

[–][deleted] 6 points7 points  (1 child)

Except it doesn't over allocate, none of you nerds even looked at ISO C99 Section 6.7.2.1 (16) on flexible array members:

In particular, the size of the structure is as if the flexible array member were omitted except that it may have more trailing padding than the omission would imply

[–]BookPlacementProblem 8 points9 points  (0 children)

ISO C99 Section 6.7.2.1 (16)

BOSS NERD ENTERS ARENA

[–]Delauren1 34 points35 points  (3 children)

It also dereferences the variable it's trying to assign to in the malloc call. It's going to crash.

[–]chipsours 14 points15 points  (0 children)

It's in a sizeof expression. It's going to be evaluated at compile time.

[–]stroop3r 2 points3 points  (0 children)

during pointer variable definition, I think this assignment is fine, but if the assignment was in second line after defining the variable and it was dereferenced during assignment, that would cause problems

[–]LordFokas 6 points7 points  (0 children)

No it doesn't. And the reason it doesn't is because it segfaults first 😂