The `new_size` may be less than the `old_size`. It will cause memory overflow in the code below. In the C library, the new size can be less than the old one. See the manual of `realloc()`:

    The contents will be unchanged to the minimum of the old and new sizes;
    newly allocated memory will be uninitialized.