News for hackers. Stuff that matters.
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by kr7 on Friday December 09, 2016 @04:01PM (#13141812)

    void *calloc(size_t count, size_t size) {
        assert(!multiplication_would_overflow(count, size));

        size_t allocation_size = count * size;
        void *allocation = malloc(allocation_size);
        memset(allocation, 0, allocation_size);
        return allocation;
    }
Should really return (void *)0 on overflow, instead of asserting.
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by AstralStorm on Saturday December 10, 2016 @02:40AM (#13144594)
And a few libc implementations have this kind of stupidity in, where in Linux there is a specialised syscall for performance reasons.
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by sp332 on Friday December 09, 2016 @05:39PM (#13142492)
I think assert() is usually used by people who are going to just turn them off during a "production" build (with -NDEBUG).
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by loeg on Friday December 09, 2016 @05:41PM (#13142509)
And GP is right that in that case, you really want calloc to return NULL rather than an overflowed (short) non-NULL allocation.